QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682478 | #5420. Inscryption | wangcq | WA | 195ms | 3940kb | C++23 | 730b | 2024-10-27 15:36:18 | 2024-10-27 15:36:19 |
Judging History
answer
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
int a[2341222];
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int x,y,z;
int i;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
x=y=1;
z=0;
for(i=1;i<=n;i++)
{
if(a[i]==-1)
{
if(y<=1&&z==0)
{
puts("-1");
goto A;
}
else if(y==1)
z--,x++;
else
y--;
}
else if(a[i]==1)
x++,y++;
else
z++;
}
if(z<y)
y-=z;
else
x=x+z-y,y=1;
printf("%d %d\n",x/gcd(x,y),y/gcd(x,y));
A:;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3940kb
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: 195ms
memory: 3888kb
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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