QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682472#5420. InscryptionwangcqWA 143ms3616kbC++23920b2024-10-27 15:35:182024-10-27 15:35:19

Judging History

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

  • [2024-10-27 15:35:19]
  • 评测
  • 测评结果:WA
  • 用时:143ms
  • 内存:3616kb
  • [2024-10-27 15:35:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		int n;
		cin>>n;
		vector<int>a(n+1);
		for(int i=1;i<=n;i++) cin>>a[i];
		int num=1,mu=1;
		int z=0;
		bool ok=1;
		for(int i=1;i<=n;i++){
			if(a[i]==1){
				num++,mu++;
			}else if(a[i]==-1){
				mu--;
				if(mu==0){
					if(z){
						z--;
						num++,mu++;
					}
				}
				if(mu==0){
					ok=0;
					break;
				}
			}else{
				z++;
			}
		}
		if(!ok){
			cout<<-1<<'\n';
			continue;
		}
		double maxx=0;
		int now_num=0,now_mu=0;
		for(int i=0;i<=z;i++){
			int j=z-i;
			int a=num+j,b=mu+j-i;
			if(b==0){
				break;
			}
			double p=a*1.0/b;
			if(p>maxx){
				maxx=p;
				now_num=a,now_mu=b;
			}
		}
		cout<<now_num/__gcd(now_num,now_mu)<<' '<<now_mu/__gcd(now_num,now_mu)<<'\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 143ms
memory: 3584kb

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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 2
5 2
1 1
-1
3 1
-1
-1
1 1
-1
6 1
3 2
-1
3 2
4 3
2 1
-1
5 3
3 1
6 1
-1
2 1
2 1
-1
1 1
-1
3 1
-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'