QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673010 | #5420. Inscryption | zttttt | WA | 459ms | 7788kb | C++14 | 1023b | 2024-10-24 20:17:37 | 2024-10-24 20:17:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int T, n, x, y;
int a[N], g[N], v[N];
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
signed main()
{
cin >> T;
while (T--){
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int pos = 0;
for (int i = n; i >= 1; i--)
if (a[i] == -1) {
pos = i;
break;
}
for (int i = pos + 1; i <= n + 1; i++) g[i] = 1;
for (int i = pos; i >= 1; i--) {
if (a[i] == -1) g[i] = g[i + 1] + 1;
else g[i] = g[i + 1] - 1;
}
x = y = 1;
int flag = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == 1) x++, y++;
else if (a[i] == -1) y--;
else {
if (y == 1) x++, y++;
else if (y - 1 >= g[i + 1]) y--;
else x++, y++;
}
if (y <= 0) {
flag = 1;
break;
}
}
if (flag) puts("-1");
else {
int g = gcd(x, y);
cout << x / g << ' ' << y / g << endl;
}
}
return 0;
}
/*
1
2
0 0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7700kb
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: 459ms
memory: 7664kb
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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