QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#496422 | #1289. A + B Problem | rollerZ | WA | 0ms | 5840kb | C++23 | 1.6kb | 2024-07-28 09:52:41 | 2024-07-28 09:52:42 |
Judging History
answer
#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
//#define int long long
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define per(i, j, k) for (int i = j; i >= k; i--)
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace std;
int read() {
int s = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return f ? s : -s;
}
int n,m,s[200005],a[100005],b[100005],pos[200005],id[200005],ans[100005],tot;
signed main() {
for(int T=read();T--;){
n=read(),m=read();
int nn=n,mm=m,top=0;tot=0;
rep(i,1,n+m)scanf("%1d",&s[i]);
rep(i,1,max(n,m))a[i]=b[i]=0;
rep(i,1,n+m)if(s[i])++top,id[pos[top]=i]=top;
rep(i,1,nn+mm){
if(!n||!m){
if(!n)a[m--]=s[i];
if(!m)a[n--]=s[i];
continue;
}
if(s[i]){
if(n<m){
if(pos[id[i]+m-n]&&nn+mm-pos[id[i]+m-n]+m-n>=m)a[n--]=1;
else b[m--]=1;
}else{
if(pos[id[i]+n-m]&&nn+mm-pos[id[i]+n-m]+n-m>=n)b[m--]=1;
else a[n--]=1;
}
}else{
if(n<m)n--;
else m--;
}
}
n=nn,m=mm;
reverse(a+1,a+n+1),reverse(b+1,b+m+1);
int j=0;
rep(i,1,max(n,m)){
ans[++tot]=(a[i]^b[i]^j)&1;
j=(a[i]+b[i]+j)>>1;
}
if(j)ans[++tot]=1;
bool flag=1;
per(i,tot,1){
flag&=!ans[i];
if(!flag)putchar(ans[i]+'0');
}
if(flag)putchar('0');
putchar('\n');
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5840kb
input:
3 4 3 1000101 2 2 1111 1 1 00
output:
1011 110 0
result:
wrong answer 1st lines differ - expected: '1101', found: '1011'