QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#250765 | #5420. Inscryption | cscnk52 | WA | 0ms | 3696kb | C++14 | 914b | 2023-11-13 17:06:28 | 2023-11-13 17:06:29 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e6 + 7;
int a[N];
int gcd(int x, int y) {
return x ? gcd(y % x, x) : y;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cnt = 0;
int ans1 = 1, ans2 = 1;
for (int i = 0; i < n; i++) {
if (a[i] == 1) {
ans1++;
ans2++;
} else if (a[i] == -1) {
if (ans2 >= 2) {
ans2--;
} else if (cnt >= 1) {
cnt--;
ans1++;
ans2++;
} else {
cout << -1 << '\n';
continue;
}
} else {
if (ans2 >= 2) {
ans2--;
cnt++;
} else {
ans1++;
ans2++;
}
}
}
int g = gcd(ans1, ans2);
cout << ans1 / g << ' ' << ans2 / g << '\n';
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3696kb
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 3 2 1 1 2 1 -1 1 1
result:
wrong answer 4th lines differ - expected: '1 1', found: '3 2'