QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#450928 | #1289. A + B Problem | ciuim | AC ✓ | 68ms | 14612kb | C++14 | 3.0kb | 2024-06-22 19:38:41 | 2024-06-22 19:38:42 |
Judging History
answer
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <random>
#include <set>
#include <ctime>
#include <map>
#include <stack>
#include <unordered_map>
#include <assert.h>
#define ll long long
#define ull unsigned long long
#define reg register
#define fo(a,b,c) for(reg ll a=b;a<=c;++a)
#define re(a,b,c) for(reg ll a=b;a>=c;--a)
#define pii pair<ll,ll>
#define pdd pair<db,db>
#define fi first
#define pb push_back
#define se second
#define ite set<pii> ::iterator
using namespace std;
const ll mod=998244353;
inline ll gi()
{
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
ll _=1;
const ll inf=1e17+5,iinf=2e9;
const ll N=2000005;
ll a[N],b[N],sum0[N],sum1[N];
char c[N];
void sol()
{
ll n=gi(),m=gi();
a[n+1]=0;
cin>>c+1;
if(n<m)
{
swap(n,m);
}
fo(i,1,n+1) a[i]=b[i]=0;
ll len=strlen(c+1);
fo(i,1,len)
{
sum0[i]=sum0[i-1];
sum1[i]=sum1[i-1];
if(c[i]=='0') sum0[i]++;
else sum1[i]++;
}
ll la=0,lb=0;
ll znn=n;
fo(i,1,len)
{
if(c[i]=='1')
{
if(n>m)
{
ll zm=m-1,zn=n,ok=1;
if(m==0) ok=0;
ll nd=zm+zn-zm-1;
if(sum0[i+nd]-sum0[i]<=zm)
{
;
}
else
{
ok=0;
}
// fo(j,i+1,len)
// {
// if(c[j]=='1') zn--;
// else
// {
// if(zm==0)
// {
// ok=0;
// break;
// }
// else
// {
// zm--;
// }
// }
// if(zn==m) break;
// }
if(ok)
{
b[m]=1;
m--;
}
else
{
a[n]=1;
n--;
}
}
else
{
ll zm=m,zn=n-1,ok=1;
if(n==0) ok=0;
ll nd=zn+zm-zn-1;
if(sum0[i+nd]-sum0[i]<=zn)
{
;
}
else
{
ok=0;
}
// fo(j,i+1,len)
// {
// if(c[j]=='1') zm--;
// else
// {
// if(zn==0)
// {
// ok=0;
// break;
// }
// else
// {
// zn--;
// }
// }
// if(zm==n) break;
// }
if(ok)
{
a[n]=1;
n--;
}
else
{
b[m]=1;
m--;
}
}
}
else
{
if(n==0||(m<n&&m))
{
b[m]=0;
m--;
}
else
{
a[n]=0;
n--;
}
}
}
// fo(i,1,znn)
// {
// cout<<a[i]<<" ";
// }cout<<'\n';
// fo(i,1,znn)
// {
// cout<<b[i]<<" ";
// }cout<<'\n';
fo(i,1,znn)
{
a[i]+=b[i];
a[i+1]+=a[i]/2;
a[i]%=2;
}
if(a[znn+1]) znn++;
while(a[znn]==0&&znn>1) znn--;
re(i,znn,1) cout<<a[i];
}
int main()
{
// freopen("partition.in","r",stdin);
// freopen("partition.out","w",stdout);
_=gi();
while(_--)
{
sol();
printf("\n");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7800kb
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: 68ms
memory: 14612kb
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