QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671094 | #5420. Inscryption | hansue# | WA | 71ms | 7916kb | C++20 | 1.8kb | 2024-10-24 10:50:51 | 2024-10-24 10:50:52 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAX=1e6+5;
int a[MAX],cnt,maxv,suf[MAX],n,pre_fc[MAX],pre_m[MAX];
int get_gcd(int x,int y){
int c=x%y;
while(c){
x=y;
y=c;
c=x%y;
}
return y;
}
int read(){
int x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-'){
f = -1;
}
c = getchar();
}
while(c >= '0' && c <= '9'){
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
void solve(){
cnt=maxv=1;
n=read();
for(int i=1;i<=n;++i)
a[i]=read();
for(int i=1;i<=n;++i){
pre_fc[i]=pre_fc[i-1];
pre_m[i]=pre_m[i-1];
if(a[i]==1||a[i]==0)
pre_fc[i]++;
else
pre_m[i]++;
// cout<<i<<" ("<<pre_fc[i]<<" "<<pre_m[i]<<endl;
}
int tmp=1e9;
suf[n]=-1;
for(int i=n;i>=1;--i){
suf[i-1]=suf[i];
if(pre_fc[i]+pre_fc[i]-pre_m[i]<tmp){
tmp=pre_fc[i]+pre_fc[i]-pre_m[i];
suf[i-1]=i;
}
}
for(int i=1;i<=n;++i){
if(a[i]==1){
cnt++;
}
if(a[i]==-1){
if(cnt==1){
printf("-1\n");
return;
}
cnt--;
maxv++;
}
if(a[i]==0){
// cout<<cnt<<" "<<i<<"^"<<suf[i]<<endl;
if(suf[i]==-1){
if(cnt>1){
cnt--;
maxv++;
}
else{
cnt++;
}
}
else
if(cnt-pre_fc[i]+pre_fc[suf[i]]>=pre_m[suf[i]]-pre_m[i]+2){
// cout<<cnt<<" "<<"**"<<cnt-pre_fc[i]+pre_fc[suf[i]]<<" "<<pre_m[suf[i]]-pre_m[i]+1<<" "<<pre_fc[i]<<" "<<pre_fc[suf[i]]<<endl;
cnt--;
maxv++;
}
else{
cnt++;
}
}
// cout<<i<<" "<<cnt<<" ! "<<maxv<<endl;
}
int t=get_gcd(maxv+cnt-1,cnt);
printf("%d %d\n",(maxv+cnt-1)/t,cnt/t);
}
int main(){
// freopen("data.in", "r", stdin);
// freopen("data.out", "w", stdout);
int T;
cin>>T;
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7916kb
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: 71ms
memory: 7908kb
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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