QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#554960 | #5420. Inscryption | HTensor# | WA | 0ms | 3528kb | C++17 | 1.4kb | 2024-09-09 18:22:31 | 2024-09-09 18:22:31 |
Judging History
answer
#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x << ": " << x << "\n"
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
const int inf = 0x3f3f3f3f3f3f3f3fLL;
void solve() {
int n; cin >> n;
vector<int> a(n + 1);
int fz = 1, fm = 1;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
int cnt = 0;
auto minus = [&]() {
--fm;
if(!fm) {
if(!cnt) return false;
else {
--cnt;
++fm; ++fz, ++fm;
}
}
return true;
};
int ans = 1;
for(int i = 1; i <= n; i++) {
if(a[i] == 1) fz++, fm++;
else if(!a[i]) {
if(!minus()) {
++fm, ++fz, ++fm;
++cnt;
}
} else {
if(!minus()) {
ans = 0; break;
}
}
}
if(!ans) {
cout << -1 << "\n";
} else {
int gcdv = __gcd(fz, fm);
cout << fz / gcdv << " " << fm / gcdv << "\n";
}
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int T; cin >> T;
while(T--) solve();
return 0;
}
/*
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
1
4
1 0 -1 0
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3528kb
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 -1 3 1 1 1 2 1 -1
result:
wrong answer 2nd lines differ - expected: '3 1', found: '-1'