QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#893988 | #1289. A + B Problem | hahyzm2008 | AC ✓ | 22ms | 20580kb | C++14 | 2.1kb | 2025-02-11 09:55:10 | 2025-02-11 09:55:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace yzm{
typedef long long ll;typedef unsigned long long ull;
typedef __int128 i28;typedef unsigned int ui;
mt19937 rd(time(0));
template <typename T>
void read(T &x){
x=0;char c=getchar();T f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
x=x*f;return;
}
template <typename T>
void write(T x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+48);
}
}using namespace yzm;
const int N = 5e6+10;
const int inf = 0x3f3f3f3f;
char s[N];
int ans[N],num[N],sum[N],pre[N],sum1[N];
int n,m,len0,len1,t,tt,tq;
int main(){
// freopen("input.txt","r",stdin);
// freopen("1.out","w",stdout);
read(t);
while(t--){
read(n);read(m);
for(int i=0;i<=n+m+1;i++){ans[i]=num[i]=pre[i]=sum[i]=sum1[i]=0;}
len0=n;len1=m;tt=0;tq=0;
if(len1>len0){swap(len0,len1);}
scanf("%s",s);
for(int i=1;i<=n+m;i++){
sum[i]=sum[i-1]+s[i-1]-'0';
sum1[i]=sum1[i-1]+((s[i-1]-'0')^1);
pre[sum1[i]]=max(pre[sum1[i]],i);
}
for(int i=1;i<=n+m;i++){
if(!pre[i])pre[i]=n+m;
}
for(int i=0;i<=n+m-1;i++){
if(s[i]=='1'){
if(len1&&sum[pre[len1-1+tt]]>=len0-len1+2+tq){ans[len1]++;len1--;}
else {ans[len0]++;len0--;if(len0<len1){swap(len0,len1);}}
tq++;
}else{
tt++;
if(len1){len1--;}
else len0--;
}
}
int x=0;
for(int i=1;i<=n+m+1;i++){
ans[i]+=x;x=ans[i]/2;ans[i]%=2;
}
bool flag=0;
for(int i=n+m+1;i>=1;i--){
if(flag||ans[i]==1){flag=1;write(ans[i]);}
}
if(!flag){putchar('0');}
puts("");
}
return 0;
}
/*
100010011
*/
/*
11111010
*/
/*
8 10
001110011111011111
10000110111
*/
/*
3 1
1011
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14160kb
input:
3 4 3 1000101 2 2 1111 1 1 00
output:
1101 110 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 22ms
memory: 20580kb
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 10000001100 1000010111 111101101 1110100000 111101010 11110000 1000011101 1001011110 10101110 101110101 11100 1111010 1000010 1011100010 10010101001 10010001 1001010 1000000010 1110 111 1111110001 10110111 1100010101 10000000 111000011 110 11111 1100101...
result:
ok 11110 lines