QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#832269 | #1289. A + B Problem | dengchengyu | AC ✓ | 27ms | 22744kb | C++14 | 2.7kb | 2024-12-25 20:07:05 | 2024-12-25 20:07:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace IO{
const int sz=1<<22;
char a[sz+5],b[sz+5],*p1=a,*p2=a,*t=b,p[205];
#define gc() (p1==p2?(p2=(p1=a)+fread(a,1,sz,stdin),p1==p2?EOF:*p1++):*p1++)
#define flush() (fwrite(b,1,t-b,stdout),t=b)
#define pc(x) (*t++=x,(t-b==sz)?flush():nullptr)
// #define gc() (getchar())
// #define flush() (1)
// #define pc(x) (putchar(x))
template<class T> inline void read(T &x){
x=0; char c=gc(),fushu=0;
while(!isdigit(c)){if(c=='-')fushu=1; c=gc();}
while(isdigit(c))x=x*10+(c^48),c=gc();
if(fushu) x=-x;
}
inline void read(char &x){
x=gc();
while(!isgraph(x))x=gc();
}
inline void read(char *x){
char c=gc();
while(!isgraph(c))c=gc();
while(isgraph(c))*x++=c,c=gc();
*x='\0';
}
inline void read(string &x){
x=""; char c=gc();
while(!isgraph(c))c=gc();
while(isgraph(c))x.push_back(c),c=gc();
}
template <typename T,typename ...Args> inline void read(T &x,Args &...args) { read(x),read(args...); }
template<class T> inline void write(T x){
if(x<0)pc('-'),x=-x;
if(!x)pc('0');
int l=0;
while(x)p[++l]=(x%10)^48,x/=10;
while(l)pc(p[l--]);
}
inline void write(char &x){pc(x);}
inline void write(const char &x){pc(x);}
inline void write(char *x){while(*x!='\0')pc(*x++);}
inline void write(const char *x){while(*x!='\0')pc(*x++);}
inline void write(string &x){for(auto c:x)pc(c);}
template <typename T,typename ...Args> inline void write(T x,Args ...args) { write(x),write(args...); }
struct F{~F(){flush();}}f;
#undef gc
#undef flush
#undef pc
};
using IO::read;
using IO::write;
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define fd(i,r,l) for(int i=(r);i>=(l);--i)
#define ll long long
#define ull unsigned long long
#define ld long double
#define it128 __int128
int T;
int n,m;
const int N=1e6+5;
char a[N<<1];
int b[N],c[N];
int cnt[N];
signed main(){
read(T);
while(T--){
read(n,m);
read(a+1);
if(n<m)swap(n,m);
fo(i,1,n+m){
cnt[i]=cnt[i-1];
if(a[i]=='1')cnt[i]++;
}
int x=n,y=m;
fo(i,1,n+m){
if(!x)c[y--]=a[i]-'0';
else if(!y)b[x--]=a[i]-'0';
else if(a[i]=='0'){
if(x<y)b[x--]=0;
else c[y--]=0;
}
else {
if(x<y){
if(cnt[n+m-x+1]-cnt[i]>=y-x+1)b[x--]=1;
else c[y--]=1;
}
else{
if(cnt[n+m-y+1]-cnt[i]>=x-y+1)c[y--]=1;
else b[x--]=1;
}
}
}
b[n+1]=0;
fo(i,1,m){
b[i]+=c[i];
}
fo(i,1,n)if(b[i]>1)b[i+1]++,b[i]-=2;
int flag=0;
fd(i,n+1,1){
if(b[i]){
flag=1,write('1');
}
else if(flag)write('0');
}
if(!flag)write('0');
write('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 13888kb
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: 27ms
memory: 22744kb
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