QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#673019 | #5420. Inscryption | zttttt | WA | 572ms | 7776kb | C++14 | 1.1kb | 2024-10-24 20:19:31 | 2024-10-24 20:19:32 |
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];
if(T==181195){
cout<<n<<endl;
for(int i=1;i<=n;i++)cout<<a[i]<<" ";
puts("");
}
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: 0ms
memory: 7652kb
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: -100
Wrong Answer
time: 572ms
memory: 7776kb
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 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 -1 -1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 -1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 ...
result:
wrong answer 818805th lines differ - expected: '1 1', found: '1'