QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176271#5420. InscryptionZhou_JKWA 139ms3472kbC++231.2kb2023-09-11 14:17:492023-09-11 14:17:50

Judging History

你现在查看的是最新测评结果

  • [2023-09-11 14:17:50]
  • 评测
  • 测评结果:WA
  • 用时:139ms
  • 内存:3472kb
  • [2023-09-11 14:17:49]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i]; 
    }
    int can_choose = 0;
    long long sum = 1;
    long long cnt = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            sum += 1;
            cnt += 1;
        }
        if (a[i] == 0) {
            can_choose += 1;
        }
        if (a[i] == -1) {
            while (cnt < 2) {
                if (can_choose == 0) {
                    cout << "-1\n";
                    return;
                }
                can_choose -= 1;
                sum += 1;
                cnt += 1;
            }
            cnt -= 1;
        }
    }
    long long w = cnt;
    while (can_choose--) {
        if (cnt > w) {
            cnt--;
        } else {
            sum += 1;
            cnt += 1;
        }
    } 
    long long x = gcd(sum, cnt);
    sum /= x;
    cnt /= x;
    cout << sum << " " << cnt << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3448kb

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: 0
Accepted
time: 139ms
memory: 3444kb

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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
1 1
-1
3 2
1 1
2 1
-1
5 3
3 1
6 1
-1
2 1
5 4
-1
1 1
-1
3 1
-1
-1
5 3
1 1
2 1
5 2
-1
4 3
4 3...

result:

wrong answer 1st lines differ - expected: '4 1', found: '5 3'