QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698121#5420. InscryptionshinonomezhouWA 123ms9876kbC++231.1kb2024-11-01 17:33:052024-11-01 17:33:06

Judging History

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

  • [2024-11-01 17:33:06]
  • 评测
  • 测评结果:WA
  • 用时:123ms
  • 内存:9876kb
  • [2024-11-01 17:33:05]
  • 提交

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;
		}
		cnt[0][n]=0,cnt[1][n]=0,cnt[2][n]=0;
		for(int i=n-1;i>=0;i--){
			for(int j=0;j<3;j++)cnt[j][i]=cnt[j][i+1];
			if(a[i]==-1)cnt[2][i]++;
			else cnt[a[i]][i]++;
		}
		pcnt[0]=0,pcnt[1]=0,pcnt[2]=0;
		for(int i=0;i<n;i++){
			if(a[i]==1){
				pcnt[1]++;
			}
			else if(a[i]==-1){
				pcnt[2]++;
			}
			else{
				if(pcnt[1]<=pcnt[2]||pcnt[1]+cnt[1][i+1]<cnt[0][i+1]+cnt[2][i+1]+pcnt[2]){
					pcnt[1]++;
				}else{
					pcnt[2]++;
				}
				
			}
		}
		int g=__gcd(1+pcnt[1],pcnt[1]-pcnt[2]+1);
		cout<<(1+pcnt[1])/g<<' '<<(pcnt[1]-pcnt[2]+1)/g<<'\n';
		
		
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9812kb

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: 123ms
memory: 9820kb

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
1
1
0
1
0
1
1
1
0
1
-1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
...

output:

1 1
-1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
-1
-1
-1
1 1
1 1
-1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 ...

result:

ok 1000000 lines

Test #3:

score: -100
Wrong Answer
time: 59ms
memory: 9876kb

input:

181249
6
1 0 -1 0 1 0
4
1 -1 -1 -1
8
-1 0 0 0 1 -1 1 1
3
0 1 0
6
1 0 -1 1 -1 0
4
1 -1 -1 -1
9
0 1 0 -1 -1 0 -1 0 1
1
-1
3
0 -1 1
5
0 0 1 -1 1
3
1 -1 0
6
-1 0 0 -1 0 1
8
1 -1 -1 -1 0 1 -1 0
2
0 0
3
-1 1 0
3
0 -1 -1
10
0 1 0 -1 1 1 0 -1 1 0
3
1 0 0
9
1 -1 1 -1 0 -1 0 0 0
3
0 1 0
3
-1 0 0
7
-1 0 -1 -1 ...

output:

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