QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#698009 | #5420. Inscryption | shinonomezhou | WA | 136ms | 9824kb | C++23 | 1.0kb | 2024-11-01 16:49:37 | 2024-11-01 16:49:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+1e2;
int a[N];
int cnt[3][N];
int pcnt[3];
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
cnt[0][n]=0,cnt[1][n]=0,cnt[2][n]=0;
// memset(cnt,0,sizeof cnt);
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;
// int sum=1,num=1;
bool flag=false;
for(int i=0;i<n;i++){
// cout<<"Y\n";
if(a[i]==1){
pcnt[1]++;
}
else if(a[i]==-1){
pcnt[2]++;
}
if(pcnt[2]>pcnt[1]){
flag=true;
break;
}
if(a[i]==0){
if(pcnt[1]+cnt[1][i+1]<=pcnt[2]+cnt[0][i+1]+cnt[2][i+1]){
pcnt[1]++;
}
else pcnt[2]++;
}
}
if(flag){
cout<<-1<<"\n";
continue;
}
else {
int g=__gcd(1+pcnt[1],pcnt[1]-pcnt[2]+1);
cout<<(1+pcnt[1])/g<<' '<<(pcnt[1]-pcnt[2]+1)/g<<'\n';
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9756kb
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: 136ms
memory: 9820kb
input:
1000000 1 1 1 -1 1 1 1 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