QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#638419#5420. InscryptiondyfhpuWA 436ms3632kbC++17798b2024-10-13 15:53:322024-10-13 15:53:33

Judging History

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

  • [2024-10-13 15:53:33]
  • 评测
  • 测评结果:WA
  • 用时:436ms
  • 内存:3632kb
  • [2024-10-13 15:53:32]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;  
#define int long long
int gcd(int a,int b) {
	if(a%b==0) return b;
	else return gcd(b,a%b);
}
void solve()
{
	int n;cin>>n;
	int a[n+10]; 
	for(int i=1;i<=n;i++) {
		cin>>a[i];
	}
	int p=1,q=1;
	int sum=0;
	bool f=0;
	for(int i=1;i<=n;i++) {
		if(a[i]==1) {
			p++;q++;
		}
		else if(a[i]==-1) {
			if(q>=2) q--;
			else {
				if(sum>=1) {
					q++;p++;q++;
					q--;
				}
				else {
					cout<<-1<<endl;
					return ;
				}
			}
		}
		else {
			if(q==1) {
				p++;q++;
			}
			else {
				sum++;q--;
			}
 		}
	}
	int x=gcd(p,q);
	cout<<p/x<<' '<<q/x<<endl;return ;
}
signed main() { 
	int t;cin>>t;
	while(t--) {
		solve();
	}
    return 0;  
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 436ms
memory: 3572kb

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

result:

wrong answer 48th lines differ - expected: '-1', found: '6 1'