QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176278#5420. InscryptionZhou_JKWA 145ms3456kbC++231.3kb2023-09-11 14:28:542023-09-11 14:28:54

Judging History

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

  • [2023-09-11 14:28:54]
  • 评测
  • 测评结果:WA
  • 用时:145ms
  • 内存:3456kb
  • [2023-09-11 14:28:54]
  • 提交

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;
    long long at_least = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            sum += 1;
            cnt += 1;
            at_least = cnt;
        }
        if (a[i] == 0) {
            at_least--;
            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;
            at_least--;
        }
    }
    at_least = max(at_least, 1LL);
    while (can_choose--) {
        if (cnt > at_least) {
            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: 3456kb

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: 145ms
memory: 3456kb

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

result:

wrong answer 17th lines differ - expected: '6 1', found: '7 3'