QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#523608 | #5420. Inscryption | BOUNCHuser | WA | 403ms | 3916kb | C++14 | 1.1kb | 2024-08-18 14:41:26 | 2024-08-18 14:41:26 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<vector>
#include<stack>
#include<sstream>
#include<cstdio>
#include <stack>
using namespace std;
int a[1000001];
int gcd(int a, int b)
{
if (a < b)
swap(a, b);
if (b == 0)
return a;
else
return gcd(b, a - b);
}
int main()
{
int T;
cin >> T;
int n,s;
bool flag;
while (T--)
{
flag = false;
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int len = 1, maxn = 1;
for (int i = 1; i <= n; i++)
{
if (a[i] == 1)
len++;
else if (a[i] == -1)
{
if (len == 1)
{
flag = true;
break;
}
else
{
len--;
maxn = maxn + 1;
}
}
else
{
if (len == 1||len==2&&a[i+1]==-1&&i+1<=n)
{
len++;
}
else
{
len--;
maxn = maxn + 1;
}
}
}
if (flag)
printf("-1\n");
else
{
if (maxn == 1)
printf("1 1\n");
else
{
int x = len - 1 + maxn;
int y = len;
int w = gcd(x,y);
printf("%d %d\n",x/w,y/w);
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
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: 403ms
memory: 3808kb
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 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