QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706909#3079. Joining The Bricks Togetherzsj08WA 1018ms4628kbC++142.0kb2024-11-03 13:55:292024-11-03 13:55:29

Judging History

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

  • [2024-11-03 13:55:29]
  • 评测
  • 测评结果:WA
  • 用时:1018ms
  • 内存:4628kb
  • [2024-11-03 13:55:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
} 
const int N=1e5+1000;
struct node{
	int id,k;
}a[N];
int n;
//int tot;
int main(){
//	freopen("i.in","r",stdin);
	int t=read();
	while(t--){
		int tot=0;
		int num1=0,num2=0;
		n=read();
		memset(a,0,sizeof a);
		for(int i=1;i<=n;i++){
			int num=read();
//			a[i].k=read();
			char s;
			cin>>s;
			if((s=='W'&&a[tot].id==1)||(s=='B'&&a[tot].id==2)){
				a[tot].k+=num;
			}
			else{
				a[++tot].k=num;
			}
//			cout<<"_____"<<s;
			if(s=='W') {
				a[tot].id=1;
				num1+=num;
			}
			else{
				a[tot].id=2;
				num2+=num;
			}
		}
//		puts("");
//		cout<<"__"<<num1<<"__"<<num2<<endl;
//		cout<<"_______";
		if(num1==0){
			printf("%d\n",num2);
			continue;
		}
		if(num2==0){
			printf("%d\n",num1);
			continue;
		}
		int res=__gcd(num1,num2);
//		cout<<res<<endl;;
		if(res==1){
			puts("1");
			continue;
		}
		num1/=res;
		num2/=res;
//		cout<<"___"<<num1<<"___"<<num2<<endl;
		int lst=a[1].k,now=0;
		int id=a[1].id;
		int ans=0;
		bool pan=false;
		for(int i=2;i<=tot;i++){
//			cout<<i<<"  "<<lst<<"   "<<id<<endl;
			if(a[i].id==id){
				lst+=a[i].k;
				continue;
			}
			if(lst==0){
				lst=a[i].k;
				id=a[i].id;
				continue;
			}
			if(id==1){
				if(lst<num1||lst%num1!=0){
					puts("1");
					pan=true;
//					cout<<"___"<<"75"<<endl;
					break;
				}
				now=num2*(lst/num1);
				if(now>a[i].k){
					puts("1");
//					cout<<"___"<<"82"<<endl;
					pan=true;
					break;
				}
				lst=a[i].k-now;
				ans++;
			}
			if(id==2){
				if(lst<num2||lst%num2!=0){
					puts("1");
					pan=true;
					break;
				}
				now=num1*(lst/num2);
				if(now>a[i].k){
					puts("1");
					pan=true;
					break;
				}
				lst=a[i].k-now;
				ans++;	
			}
			id=a[i].id;
		}
		if(!pan) printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1018ms
memory: 4628kb

input:

44279
1
1 B
1
1 W
2
1 B
1 W
2
1 W
1 W
3
1 B
1 B
1 W
3
1 W
1 B
1 W
3
1 B
1 W
1 W
3
1 W
1 W
1 W
4
1 B
1 B
1 B
1 W
4
1 W
1 B
1 B
1 W
4
1 B
1 W
1 B
1 W
4
1 W
1 W
1 B
1 W
4
1 B
1 B
1 W
1 W
4
1 W
1 B
1 W
1 W
4
1 B
1 W
1 W
1 W
4
1 W
1 W
1 W
1 W
5
1 B
1 B
1 B
1 B
1 W
5
1 W
1 B
1 B
1 B
1 W
5
1 B
1 W
1 B
1 B
...

output:

1
1
1
2
1
1
1
3
1
2
2
1
1
1
1
4
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
5
1
2
1
2
2
3
3
1
1
3
3
1
2
1
1
1
1
2
2
2
1
1
2
1
1
1
1
1
1
1
1
6
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
7
1
2
1
1
1
1
1
2
2
1
1
1
1
3
3
1
1
1
1
3
1
4
...

result:

wrong answer 35th lines differ - expected: '2', found: '1'