QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#431405 | #1289. A + B Problem | chenxinyang2006 | AC ✓ | 55ms | 4476kb | C++20 | 1.9kb | 2024-06-05 14:34:48 | 2024-06-05 14:34:48 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int T,n,m,L;
char s[200005];
int ans[200005];
void solve(){
scanf("%d%d",&n,&m);
scanf("%s",s + 1);
if(n < m) swap(n,m);
int j = m,bst = 0;
rep(k,1,n){
if(s[m + k] == '1'){
bst = k;
continue;
}
while(j && s[j] == '0') j--;
if(!j) break;
if(m - j > n - k) break;
j--;
bst = k;
}
// printf("%d ",bst);
L = 0;
int lim = m + bst;
per(k,lim,1){
if(s[k] == '1'){
if(bst) bst--;
else ans[++L]++;
}else{
++L;
}
}
// printf("L=%d\n",L);
assert(L == m);
// rep(i,1,L) printf("%d",ans[i]);
// printf("\n");
L = 0;
per(k,n + m,lim + 1) ans[++L] += s[k] - '0';
rep(k,1,lim - m) ans[++L]++;
rep(k,1,L){
if(ans[k] >= 2){
ans[k] -= 2;
ans[k + 1]++;
}
if(k == L && ans[k + 1]) L++;
}
while(L && !ans[L]) L--;
if(!L){
printf("0");
}else{
per(i,L,1){
printf("%d",ans[i]);
ans[i] = 0;
}
}
printf("\n");
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d",&T);
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
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: 55ms
memory: 4476kb
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