QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#612154#5420. Inscryptionice_cup#WA 130ms5704kbC++14724b2024-10-05 08:40:072024-10-05 08:40:09

Judging History

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

  • [2024-10-05 08:40:09]
  • 评测
  • 测评结果:WA
  • 用时:130ms
  • 内存:5704kb
  • [2024-10-05 08:40:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MID int mid=(l+r)>>1;
#define ls p<<1
#define rs p<<1|1
#define endl '\n'
int n,s[1001000],c[1001000];
void solve(){
	cin>>n;
	int a=1,b=1;
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	s[n+1]=0;
	for(int i=n;i>=1;i--){
		s[i]=s[i+1]+c[i];
	}
	for(int i=1;i<=n;i++){
		int x=c[i];
		if(x==1)a++,b++;
		if(x==-1){
			if(b==1){
				cout<<-1<<endl;
				return;
			}
			else b--;
		}
		if(x==0){
			if(b==1||b+s[i]<=1){
				a++,b++;
			}
			else b--;
		}
	}
	int d=__gcd(a,b);
	cout<<a/d<<' '<<b/d<<endl;
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int TTT;
	cin>>TTT;
	while(TTT--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 130ms
memory: 5704kb

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

result:

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