QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#210264 | #5420. Inscryption | kokomiisbest | WA | 476ms | 3668kb | C++14 | 1.6kb | 2023-10-11 10:18:44 | 2023-10-11 10:18:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int a[3];
//ֻ\xc2\xdbƽ\xbe\xf9\xca\xfd\xa3\xac\xca¼\xfe-1\xca\xc7\xd5\xfd\xb9\xb1\xcfģ\xa1
//\xc8\xe7\xb9\xfbcnt(-1)=cnt(1) \xca\xc7\xc0\xed\xc2\xdb\xd7\xee\xd3ŵ\xc4 \xcb\xf9\xd2\xd40\xb5ı仯Ҫ\xbe\xa1\xc1\xbf\xcd\xf9\xd5\xe2\xc9\xcf\xc3濿\xa3\xa1
// \xb2\xa2\xc7\xd2ÿ\xc2\xd6\xd6\xd0cnt(-1)<=cnt(1) \xb7\xf1\xd4\xf2\xca\xc7\xce\xdeЧ\xb5ģ\xa1\xbc\xb4\xce\xa8\xcd\xea\xb3\xc9\xcb\xf9\xd3\xd0\xca¼\xfe\xa3\xa1\xca\xe4\xb3\xf6-1\xa3\xa1
//\xcfȱ\xa3֤\xb6\xbc\xc4\xdc\xcd\xea\xb3\xc9 Ȼ\xba\xf3\xb7\xd6\xc5䣿
int gcd(int a,int b)
{
return b>0 ? gcd(b,a%b):a;
}
void solve(){
int n;
cin>>n;
bool can = true;
for(int i=0;i<3;i++) a[i]=0;
a[1]=1;
for(int i=0;i<n;i++){
int x;
cin>>x;
if(x==-1) a[2]++;
if(x==1) a[1]++;
if(x==0) a[0]++;
if(a[2]>=(a[0]+a[1])) can=false;
}
if(!can){
cout<<-1<<endl;
return;
}
// cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
int dif = a[1]-a[2]-1;
if(dif>a[0]){
int x=a[1],y=a[1]-a[2]-a[0];
int m=gcd(x,y);
cout<<x/m<<" "<<y/m<<endl;
return;
}
else if(dif>=0){
a[2]+=dif;
a[0]-=dif;
if(a[0]%2){
a[1]+=a[0]/2+1;
int m=gcd(a[1],2);
cout<<a[1]/m<<" "<<2/m<<endl;
return;
}else{
a[1]+=a[0]/2;
cout<<a[1]<<" "<<1<<endl;
}
}else{
a[1]-=dif;
a[0]+=dif;
if(a[0]%2){
a[1]+=a[0]/2+1;
int m=gcd(a[1],2);
cout<<a[1]/m<<" "<<2/m<<endl;
return;
}
else{
a[1]+=a[0]/2;
cout<<a[1]<<" "<<1<<endl;
}
}
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
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: 476ms
memory: 3600kb
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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