QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250042#5420. Inscryptioncscnk52WA 138ms3588kbC++14925b2023-11-12 20:45:152023-11-12 20:45:16

Judging History

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

  • [2023-11-12 20:45:16]
  • 评测
  • 测评结果:WA
  • 用时:138ms
  • 内存:3588kb
  • [2023-11-12 20:45:15]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e6+7;
int a[N];
int gcd(int x, int y) {
	return x ? gcd(y % x, x) : y;
}
signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int flag=0;
		int sum=1 , total=1;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]==1) 
			{
				sum+=1;
				total+=1;
			}
			else if(a[i]==0)
			{
				sum+=1;
				a[i]=2;
				total+=1;
			}
			else
			{
				sum-=1;
				if(sum==0) flag=1;
			}
		}
		if(flag==1)
		{
			cout<<-1<<endl;
			continue;
		}
		int res=sum;
		for(int i=n;i>=1;i--)
		{
			if(res>2&&a[i]==2)
			{
				res-=2;
				sum-=2;
				total-=1;
			}else if(a[i]==1||a[i]==2)
			{
				res--;
			}
		}
		cout << total / (gcd(total, sum)) << ' ' << sum / gcd(total, sum) << endl;
	}	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 138ms
memory: 3432kb

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

result:

wrong answer 1st lines differ - expected: '4 1', found: '5 3'