QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#261664 | #5420. Inscryption | vp_account# | WA | 69ms | 5988kb | C++14 | 718b | 2023-11-23 07:54:19 | 2023-11-23 07:54:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=1e6+5;
int n,cur,A,B,g,a[M],f[M];
int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x*f;
}
void solve(){ n=read();cur=0;
for (int i=1;i<=n;i++) a[i]=read();
for (int i=n;i;i--){
if (!~a[i]) cur--;
else cur++;
f[i]=cur;
} A=B=1; f[n+1]=0;
if (cur<=0) return puts("-1"),void();
for (int i=1;i<=n;i++){
if (!~a[i]) B--;
else if (a[i]) A++,B++;
else if (B-1<=max(f[i+1],0))
A++,B++;
else B--;
}
g=__gcd(A,B);
printf("%d %d\n",A/g,B/g);
}
int main(){int T=read();
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5844kb
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: 69ms
memory: 5988kb
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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