QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698232#5420. InscryptionshinonomezhouWA 130ms3736kbC++23935b2024-11-01 18:17:122024-11-01 18:17:13

Judging History

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

  • [2024-11-01 18:17:13]
  • 评测
  • 测评结果:WA
  • 用时:130ms
  • 内存:3736kb
  • [2024-11-01 18:17:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+1e2;
ll a[N];
//ll cnt[3][N];
ll pcnt[3];
//ll p[3];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		ll n;
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		pcnt[0]=0,pcnt[1]=0,pcnt[2]=0;
		bool flag=false;
		for(int i=0;i<n;i++){
			if(a[i]==-1)pcnt[2]++;
			else pcnt[a[i]]++;
			if(pcnt[0]+pcnt[1]<pcnt[2]){
				flag=true;
				break;
			}
		}
		if(flag){
			cout<<-1<<"\n";
			continue;
		}
		int cnt1=pcnt[0]+pcnt[1],cnt2=pcnt[2];
		for(int i=n-1;i>=0;i--){
			if(a[i]==0){
				if(cnt1-1>=cnt2+1&&pcnt[0]+pcnt[1]-1>=pcnt[2]+1){
					cnt1--;
					cnt2++;
				}
				pcnt[0]--;
			}
			else if(a[i]==-1)pcnt[2]--;
			else if(a[i]==1) pcnt[1]--;
		}
		
		int g=__gcd(1+cnt1,cnt1-cnt2+1);
		cout<<(1+cnt1)/g<<' '<<(cnt1-cnt2+1)/g<<'\n';
		
		
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3680kb

input:

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

result:

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