QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#450519#1289. A + B Problemdo_while_trueAC ✓218ms21000kbC++202.9kb2024-06-22 14:54:542024-06-22 14:54:54

Judging History

你现在查看的是最新测评结果

  • [2024-06-22 14:54:54]
  • 评测
  • 测评结果:AC
  • 用时:218ms
  • 内存:21000kb
  • [2024-06-22 14:54:54]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
	r=0;bool w=0;char ch=getchar();
	while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
	return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
	int s=1;
	while(y){
		if(y&1)s=1ll*s*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return s;
}
const int N=2000010;
int n,m,len;
int a[N],b[N],c[N];
char str[N];
int ans[N],A[N],B[N];
void solve(int t,int *f){
	int u=n,v=m;
	for(int i=1;i<=len;i++){
		int op=0;
		if(v==0)op=0;
		else if(u==0)op=1;
		else{
			if(!c[i])op=u<v?0:1;
			else op=u<v?1:0;
		}
		if(i<=t)op=1;
		if(op==0)a[u--]=c[i];
		else b[v--]=c[i];
	}
	for(int i=1;i<=n;i++)f[i]=a[i]+b[i];
	f[n+1]=0;
}
int check(){
	for(int i=n;i>=1;i--){
		if(A[i]!=B[i])
			return A[i]>B[i];
	}
	return 1;
}
void solve(){
	read(n,m);
	if(n<m)swap(n,m);
	len=n+m;
	for(int i=1;i<=len+2;i++)ans[i]=a[i]=b[i]=A[i]=B[i]=0;
	scanf("%s",str+1);
	for(int i=1;i<=len;i++)c[i]=str[i]-'0';
	vi vec;
	vec.pb(0);
	for(int i=1;i<=m;i++)if(c[i])vec.pb(i);
	int l=1,r=(int)vec.size()-1,mid,as=0;
	while(l<=r){
		mid=(l+r)>>1;
		solve(vec[mid],A);
		solve(vec[mid-1],B);
		if(check())as=mid,l=mid+1;
		else r=mid-1;
	}
	solve(vec[as],ans);
	for(int i=1;i<=n;i++){
		ans[i+1]+=ans[i]/2;
		ans[i]%=2;
	}
	if(ans[n+1])++n;
	while(n&&!ans[n])--n;
	if(n==0)puts("0");
	else{
		for(int i=n;i>=1;i--)cout<<ans[i];
		cout<<'\n';
	}
}
signed main(){
	int T;read(T);
	while(T--)solve();
    #ifdef do_while_true
//		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 15964kb

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: 218ms
memory: 21000kb

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