QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638434#5420. InscryptiondyfhpuWA 475ms3684kbC++17798b2024-10-13 15:55:272024-10-13 15:55:32

Judging History

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

  • [2024-10-13 15:55:32]
  • 评测
  • 测评结果:WA
  • 用时:475ms
  • 内存:3684kb
  • [2024-10-13 15:55:27]
  • 提交

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;  
}

详细

Test #1:

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

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: 475ms
memory: 3684kb

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

result:

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