QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831163 | #1289. A + B Problem | 2021cyq | TL | 0ms | 11744kb | C++14 | 3.4kb | 2024-12-25 11:22:16 | 2024-12-25 11:22:17 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bll __int128
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define sec second
#define vii vector<int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pii pair<int,int>
#define pil pair<int,ll>
#define re register
#define puu pair<ull,ull>
#define clr clear
#define vpi vector<pii>
#define qii queue<int>
using namespace std;
namespace io{
const int __SIZE=(1<<22)+1;
char ibuf[__SIZE],*iS,*iT,obuf[__SIZE],*oS=obuf,*oT=oS+__SIZE-1,__c,qu[55];int __f,qr,_eof;
#define Gc()(iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,__SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
inline void flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
inline void gc(char&x){x=Gc();}
inline void pc(char x){*oS++=x;if(oS==oT)flush();}
inline void pstr(const char*s){int __len=strlen(s);for(__f=0;__f<__len;++__f)pc(s[__f]);}
inline void gstr(char*s){for(__c=Gc();__c<32||__c>126||__c==' ';)__c=Gc();
for(;__c>31&&__c<127&&__c!=' ';++s,__c=Gc())*s=__c;*s=0;}
template<class I>inline bool read(I&x){_eof=0;
for(__f=1,__c=Gc();(__c<'0'||__c>'9')&&!_eof;__c=Gc()){if(__c=='-')__f=-1;_eof|=__c==EOF;}
for(x=0;__c<='9'&&__c>='0'&&!_eof;__c=Gc())x=x*10+(__c&15),_eof|=__c==EOF;x*=__f;return!_eof;}
template<class I>inline void write(I x){if(!x)pc('0');if(x<0)pc('-'),x=-x;
while(x)qu[++qr]=x%10+'0',x/=10;while(qr)pc(qu[qr--]);}
struct Flusher_{~Flusher_(){flush();}}io_flusher_;
}using io::pc;using io::gc;using io::pstr;using io::gstr;using io::read;using io::write;
const int N=2e6+5;
string str;
int t,n,m,s1,s2,len;
int a[N],b[N],c[N],bz[N],ans[N];
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>t;
int sss=0;
while(t--)
{
cin>>n>>m>>str,str=' '+str,sss++;
if(n>m)swap(n,m);
for(int i=1;i<=n+m;i++)ans[i]=0;
for(int i=1;i<=n;i++)
{
s1=n,s2=m;int l=0;
for(int j=1;j<=i;j++)a[s1--]=str[++l]-'0';
b[s2--]=str[++l]-'0';
while(l<n+m)
{
if(s1>s2)
{
while(s2&&str[l+1]=='0')b[s2--]=str[++l]-'0';
a[s1--]=str[++l]-'0';
}
else
{
while(s1&&str[l+1]=='0')a[s1--]=str[++l]-'0';
b[s2--]=str[++l]-'0';
}
}
for(int j=1;j<=n+m;j++)c[j]=0;
for(int j=1;j<=n;j++)c[j]+=a[j];
for(int j=1;j<=m;j++)c[j]+=b[j];
for(int j=1;j<=n+m;j++)if(c[j]>=2)c[j]-=2,c[j+1]++;
int bz=0;
for(int j=n+m;j>=1;j--)
{
if(c[j]>ans[j]){bz=1;break;}
if(c[j]<ans[j])break;
}
if(bz)for(int j=1;j<=n+m;j++)ans[j]=c[j];
}
for(int i=1;i<=m;i++)
{
s1=n,s2=m;int l=0;
for(int j=1;j<=i;j++)b[s2--]=str[++l]-'0';
a[s1--]=str[++l]-'0';
while(l<n+m)
{
if(s1>s2)
{
while(s2&&str[l+1]=='0')b[s2--]=str[++l]-'0';
a[s1--]=str[++l]-'0';
}
else
{
while(s1&&str[l+1]=='0')a[s1--]=str[++l]-'0';
b[s2--]=str[++l]-'0';
}
}
for(int j=1;j<=n+m;j++)c[j]=0;
for(int j=1;j<=n;j++)c[j]+=a[j];
for(int j=1;j<=m;j++)c[j]+=b[j];
for(int j=1;j<=n+m;j++)if(c[j]>=2)c[j]-=2,c[j+1]++;
int bz=0;
for(int j=n+m;j>=1;j--)
{
if(c[j]>ans[j]){bz=1;break;}
if(c[j]<ans[j])break;
}
if(bz)for(int j=1;j<=n+m;j++)ans[j]=c[j];
}
int nd=-1;
for(int i=n+m;i>=1;i--)if(ans[i]){nd=i;break;}
if(nd==-1){cout<<"0\n";continue;}
for(int i=nd;i>=1;i--)cout<<ans[i];
cout<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11744kb
input:
3 4 3 1000101 2 2 1111 1 1 00
output:
1101 110 0
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
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...