QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#682478#5420. InscryptionwangcqWA 195ms3940kbC++23730b2024-10-27 15:36:182024-10-27 15:36:19

Judging History

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

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

answer

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
	int a[2341222];
	int gcd(int a,int b)
	{
		return b==0?a:gcd(b,a%b);
	}
int main()
{
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int x,y,z;
		int i;	
		for(i=1;i<=n;i++)
	scanf("%d",&a[i]);
		x=y=1;
		z=0;
		for(i=1;i<=n;i++)
			{
				if(a[i]==-1)
				{
					if(y<=1&&z==0)
					{
					
					puts("-1");
					goto A;
					}
					else if(y==1)
					z--,x++;
				else
				y--;
					
				}
				else if(a[i]==1)
				x++,y++;
				else
				z++;
			}
			if(z<y)
			y-=z;
			else
			x=x+z-y,y=1;
		printf("%d %d\n",x/gcd(x,y),y/gcd(x,y));
			A:;
	}
 return 0;
}

详细

Test #1:

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

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: 195ms
memory: 3888kb

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
0
1
-1
1
0
1
-1
1
0
1
0
1
0
1
0
1
0
1
-1
1
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4th lines differ - expected: '3 2', found: '2 1'