QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106423 | #5420. Inscryption | wsygxlj | WA | 3ms | 9776kb | C++14 | 1.3kb | 2023-05-17 18:26:03 | 2023-05-17 18:26:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int c1[1000006],c2[1000005],a[1000005],cs[1000006];
int main()
{
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
c1[i]=c2[i]=0,cs[i]=0;
}
c1[n+1]=c2[n+1]=0;
for(int i=n;i>0;i--)
{
if(a[i]==1)
{
c2[i]=c2[i+1];c1[i]=c1[i+1]+1;
}
else {
c2[i]=c2[i+1]+1;c1[i]=c1[i+1];
}
if(a[i]==-1) cs[i]=cs[i+1]+1;
// cout<<c1[i]<<" "<<c2[i]<<endl;
}
int f=1;
long long c=1,b=1;
for(int i=1;i<=n;i++)
{
//cout<<c<<" "<<b<<" "<<c1[i]<<" "<<c2[i]<<endl;
if(a[i]==1) c++,b++;
else if(a[i]==-1)
{
if(b>=2) b--;
else
{
f=0;break;
}
}
else
{
if(b+c1[i]>=c2[i]+1&&b>=2&&b>=cs[i+1]+2) b--;
else c++,b++;
}
}
if(f)
{
long long g=__gcd(c,b);
printf("%lld %lld\n",c/g,b/g);
}
else printf("-1\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 9776kb
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 1 1 -1
result:
wrong answer 5th lines differ - expected: '2 1', found: '1 1'