QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693394 | #5420. Inscryption | UItace# | WA | 62ms | 3792kb | C++17 | 2.0kb | 2024-10-31 16:04:29 | 2024-10-31 16:04:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;
const int inf = 1e9;
const int N = 2e5 + 5;
int read() {
int x = 0, t = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
t = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * t;
}
void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
void solve() {
int n;
n = read();
vector<int> v(n + 1, 0);
for (int i = 1; i <= n; ++i) v[i] = read();
auto Max = [&](pii a, pii b) -> pii {
if (a.first * b.second > b.first * a.second)return a;
else return b;
};
int sum = 1, cnt = 1, zero = 0;
for (int i = 1; i <= n; ++i) {
if (v[i] == 1) ++sum, ++cnt;
else if (!v[i]) ++zero;
else {
if (cnt == 1) {
if (zero) --zero, ++sum;//1.
else {
cout << -1 << endl;
return;
}
} else --cnt;
}
}
pii res = {1, inf};
for (int i = 0; i <= zero; ++i) {
if (cnt + 2 * i - zero > 0) {
pii tmp = {sum + i, cnt - zero + 2 * i};
int tmpG = gcd(tmp.first, tmp.second);
tmp.first /= tmpG, tmp.second /= tmpG;
res = Max(res, tmp);
}
}
int g = __gcd(res.first, res.second);
res.first /= g, res.second /= g;
write(res.first), putchar(' '), write(res.second), putchar('\n');
// cout << res.first << ' ' << res.second << endl;
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
_ = read();
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory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