QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#673027 | #5420. Inscryption | zttttt | WA | 495ms | 7732kb | C++14 | 1.1kb | 2024-10-24 20:20:44 | 2024-10-24 20:20: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;
int T1=T;
while (T--){
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
if(T1!=1000000&&T==181195){
cout<<n<<endl;
for(int i=1;i<=n;i++)cout<<a[i]<<" ";
puts("");
continue;
}
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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7712kb
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: 495ms
memory: 7732kb
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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