QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645668#5420. InscryptiontsaiWA 161ms3916kbC++14767b2024-10-16 19:23:292024-10-16 19:23:31

Judging History

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

  • [2024-10-16 19:23:31]
  • 评测
  • 测评结果:WA
  • 用时:161ms
  • 内存:3916kb
  • [2024-10-16 19:23:29]
  • 提交

answer

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

int a[1000050]={0};

void solve(){
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int zero=0;
	int num=1;
	int sum=1;
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			zero++;
		}else if(a[i]==1){
			sum++;
			num++;
		}else{
			num--;
		}
		if(num<=0){
			zero--;
			num++;
			sum++;
		}
		if(zero<0){
			printf("-1");
			return;
		}
	}
	if(zero>0){
		int tem=min(num-1,zero);
		num-=tem;
		zero-=tem;			
	}
	if(zero%2==0){
		sum+=zero/2;
	}else{
		sum+=zero/2;
		num++;
		sum++;
	}
	int x=__gcd(num,sum);
	printf("%d %d",sum/x,num/x);
}

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		solve();
		if(t) printf("\n");
	}
	
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
7
1 1 1 -1 1 1 -1
4
1 0 -1 0
4
0 -1 -1 0
1
0
2
0 0
1
-1

output:

3 2
3 1
-1
1 1
2 1
-1

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 161ms
memory: 3916kb

input:

1000000
1
1
1
-1
1
1
1
1
1
1
1
1
1
-1
1
-1
1
0
1
0
1
1
1
0
1
-1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
0
1
0
1
1
1
-1
1
1
1
1
1
-1
1
0
1
1
1
0
1
-1
1
0
1
-1
1
1
1
-1
1
0
1
1
1
1
1
-1
1
0
1
-1
1
-1
1
-1
1
-1
1
0
1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
-1
-1
4 1
1 1
2 1
5 2
-1
3 1
4 3...

result:

wrong answer 28th lines differ - expected: '5 4', found: '2 1'