Anton and School
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input
4
6 8 4 4
16 22 10 10
output
3 5 1 1 
input
5
8 25 14 7 16
19 6 9 4 25
output
-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的更多相关文章

  1. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

  2. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  7. 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 ...

  8. 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 ...

  9. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

  10. 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 ...

随机推荐

  1. 主题: jQuery异步调用KindEditor无法赋值【解决】

    KindEditor.ready(function (K) { window.editor1 = K.create('#tjssjs', { width: '480px', height: '150p ...

  2. Mysql表名区分大小写

    mysql数据库在windows服务器上表名和字段名均不区分大小写, 但在linux服务器上表名默认是区分大小写的,可在/etc/my.cnf文件中的[mysqld]下面加上一条配置 lower_ca ...

  3. List container

    //List容器 //List本质是一个双向链表 //构造函数 list<int>c0; //空链表 list<int>c1(3); //建一个含三个默认值是0的元素链表 li ...

  4. 万航单位换算器 V1.0 绿色版

    软件名称: 万航单位换算器软件语言: 简体中文授权方式: 免费软件运行环境: Win 32位/64位软件大小: 347KB图片预览: 软件简介:万航单位换算器是一个可以随意转换单位的绿色软件,这个软件 ...

  5. 2015 Multi-University Training Contest 10

    1001 CRB and Apple 1002 CRB and Candies 1003 CRB and Farm 1004 CRB and Graph 1005 CRB and His Birthd ...

  6. ural 1203. Scientific Conference(动态规划)

    1203. Scientific Conference Time limit: 1.0 second Memory limit: 64 MB Functioning of a scientific c ...

  7. (译)UEFI 启动:实际工作原理

    本文是我翻译自国外技术博客的一篇文章,其中讲述了 UEFI 的一些基本概念和细节. 本文的原始链接位于: https://www.happyassassin.net/2014/01/25/uefi-b ...

  8. MFC滚动条实现要点

    MFC滚动条实现要点 1.鼠标拖动滚动条从而滚动窗口,需要实现CDialog::OnVScroll()函数.根据传入参数nPos,计算滚动距离.最后再调用ScrollWindow()和SetScrol ...

  9. C# 处理图片 不规则图形裁剪

    最近项目要求实现不规则裁剪功能.本来想用html5的canvas在前端实现的,但是发现有点困难,以下为C#端对图对片的处理. 为了让大家知道下面内容是否是自己想要的,我先发效果图. 原图 通过下面代码 ...

  10. Linux下将Mysql和Apache加入到系统服务里的方法

    Apache加入到系统服务里面: cp /安装目录下/apache/bin/apachectl /etc/rc.d/init.d/httpd 修改httpd 在文件头部加入如下内容: ### # Co ...