QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684159 | #5420. Inscryption | nageing | WA | 178ms | 3832kb | C++20 | 1.3kb | 2024-10-28 11:01:20 | 2024-10-28 11:01:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
bool chmin(int &a, int b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
void solve(int T) {
int n;
cin >> n;
vector<int> a(n);
map<int, int> cnt;
for (int i = 0; i < n; i ++) {
cin >> a[i];
cnt[a[i]] ++;
}
if (T == 28) {
cout << n << '\n';
for (int i = 0; i < n; i ++) {
cout << a[i] << " \n"[i == n - 1];
}
return;
}
int p = 1, q = 1, t = 0;
for (int i = 0; i < n; i ++) {
if (a[i] == 1) {
p ++;
q ++;
} else if (a[i] == -1) {
if (q + t < 2) {
cout << -1 << '\n';
return;
} else {
if (q < 2) {
t --;
p ++;
} else {
q --;
}
}
} else {
t ++;
}
}
//cout << p << ' ' << q << ' ' << t << '\n';
if (q - 1 >= t) {
q = q - t;
} else {
if ((q + t) % 2) {
p = p + (q + t + 1) / 2 - q;
q = 1;
} else {
//cout << "there\n";
p = p + (q + t + 2) / 2 - q;
q = 2;
}
}
//cout << p << ' ' << q << '\n';
int g = __gcd(p, q);
cout << p / g << ' ' << q / g << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i ++) {
solve(i);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 178ms
memory: 3832kb
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 0 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 28th lines differ - expected: '1 1', found: '1'