QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#496435 | #1289. A + B Problem | rollerZ | WA | 96ms | 6796kb | C++23 | 1.6kb | 2024-07-28 10:12:03 | 2024-07-28 10:12:04 |
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;
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');
rep(i,1,top)pos[i]=id[pos[i]]=0;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5732kb
input:
3 4 3 1000101 2 2 1111 1 1 00
output:
1101 110 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 96ms
memory: 6796kb
input:
11110 10 8 111011010011100100 3 5 01011000 7 6 1110101010000 9 1 0110100101 1 9 0100001110 8 10 000101101011111000 9 6 011111111000111 1 9 1011101101 10 7 00100011000100000 4 9 1000101101010 8 4 100100110000 8 9 00101111011000101 8 9 11000000101011110 7 6 1111010100110 2 9 01001110101 4 5 100010100 ...
output:
10011010100 11100 10101000 110100101 100001110 1111111000 1000010111 111101101 1110100000 111101010 11110000 1000010101 1001011110 10101110 101110101 10100 1111010 1000010 1011011110 10010101001 10001001 111100 111111010 1110 111 1111110001 10110111 1100010101 1110000 111000011 110 11111 11001010 11...
result:
wrong answer 6th lines differ - expected: '10000001100', found: '1111111000'