Anton and School
2 seconds
256 megabytes
standard input
standard output
Anton goes to school, his favorite lessons are arraystudying. He usually solves all the tasks pretty fast, but this time the teacher gave him a complicated one: given two arrays b and c of length n, find array a, such that:
where a and b means bitwise AND, while a or b means bitwise OR.
Usually Anton is good in arraystudying, but this problem is too hard, so Anton asks you to help.
The first line of the input contains a single integers n (1 ≤ n ≤ 200 000) — the size of arrays b and c.
The second line contains n integers bi (0 ≤ bi ≤ 109) — elements of the array b.
Third line contains n integers ci (0 ≤ ci ≤ 109) — elements of the array c.
If there is no solution, print - 1.
Otherwise, the only line of the output should contain n non-negative integers ai — elements of the array a. If there are multiple possible solutions, you may print any of them.
4
6 8 4 4
16 22 10 10
3 5 1 1
5
8 25 14 7 16
19 6 9 4 25
-1
分析:可以证明答案数组是a[i]=(b[i]+c[i]+Σ(b[i]+c[i])/(2n))/n;
然后根据异或合取性质检验答案;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,t;
ll a[maxn],b[maxn],c[maxn],d[maxn],k[maxn],num[][maxn],sum;
bool flag;
int main()
{
int i,j;
flag=true;
scanf("%d",&n);
rep(i,,n)b[i]=read();
rep(i,,n)c[i]=read();
rep(i,,n)d[i]=b[i]+c[i],sum+=d[i];
sum/=(*n);
rep(i,,n)a[i]=(d[i]-sum)/n;
rep(i,,n)
{
rep(j,,)if((a[i]>>j)&)num[j][i]=,k[j]++;
}
rep(i,,n)
{
ll tmp1=,tmp2=;
rep(j,,)
{
if(num[j][i])tmp1+=(<<j)*k[j];
else tmp2+=(<<j)*k[j];
}
if(tmp1!=b[i]&&tmp2!=c[i])
{
flag=false;
break;
}
}
if(flag)
{
rep(i,,n)printf("%lld ",a[i]);
}
else puts("-1");
//system("Pause");
return ;
}
Anton and School的更多相关文章
- Codeforces 734E. Anton and Tree 搜索
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- Codeforces Round #379 (Div. 2) E. Anton and Tree 缩点 直径
E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a t ...
- Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- Codeforces Round #379 (Div. 2) A. Anton and Danik 水题
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟
题目链接: http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test4 secondsmem ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- Codeforces Round #379 (Div. 2) E. Anton and Tree 树的直径
E. Anton and Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- Python之异步IO&RabbitMQ&Redis
协程: 1.单线程运行,无法实现多线程. 2.修改数据时不需要加锁(单线程运行),子程序切换是线程内部的切换,耗时少. 3.一个cpu可支持上万协程,适合高并发处理. 4.无法利用多核资源,因为协程只 ...
- UESTC 1272 Final Pan's prime numbers(乱搞)
题目链接 Description Final Pan likes prime numbers very much. One day, he want to find the super prime n ...
- C库 - 常用文件IO函数
#include<stdio.h> 0. 文件打开关闭FILE *fp = fopen("C:\\a.dat","wb+");fclose(fp); ...
- 如何将编译出来的images拷贝到windows下面刷机
由于SPRD的刷机工具ResearchDownload运行在window环境下:这样,我们平时在开发环境下编译出来的镜像文件就不能直接用于刷机了. 这里涉及到一个双系统中文件共享的方法.由于企业信息安 ...
- 解决 .NET Core 中 GetHostAddressesAsync 引起的 EnyimMemcached 死锁问题
在我们将站点从 ASP.NET + Windows 迁移至 ASP.NET Core + Linux 的过程中,目前遇到的最大障碍就是 —— 没有可用的支持 .NET Core 的 memcached ...
- yii2图片验证码
控制器LoginController.php <?php namespace backend\controllers; use Yii; use yii\debug\models\search\ ...
- centos 安装ftp服务器
CentOS下搭建FTP服务器简单记录. 1.安装vsftpd yum install vsftpd 2.编辑iptablesvi /etc/sysconfig/iptables -A INPUT - ...
- MySQL5.7以上开启binlog
在my.cnf的mysqld下加入: server_id = 0 log_bin=/harddisk/mysql_data/mysql_binlog/mysql-bin binlog_format ...
- oracle 同义词
同义词概念 Oracle的同义词(synonyms)从字面上理解就是别名的意思,和视图的功能类似,就是一种映射关系.它可以节省大量的数据库空间,对不同用户的操作同一张表没有多少差别;它扩展了数据库的使 ...
- jdk and tomcat 环境变量配置
一.安装JDK和Tomcat 1,安装JDK:直接运行jdk-7-windows-i586.exe可执行程序,默认安装即可. 备注:路径可以其他盘符,不建议路径包含中文名及特殊符号. 2.安装Tomc ...