QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#182849#5420. InscryptionKAZE_mae#WA 297ms3640kbC++17881b2023-09-18 16:58:382023-09-18 16:58:38

Judging History

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

  • [2023-09-18 16:58:38]
  • 评测
  • 测评结果:WA
  • 用时:297ms
  • 内存:3640kb
  • [2023-09-18 16:58:38]
  • 提交

answer

#include <bits/stdc++.h> 
using namespace std;


void solve() {
    int n, sum = 1, cnt = 1, ql = 0, ans = 0;
    cin>> n;
    for(int i = 0; i < n; ++ i) {
        int op;
        cin>> op;
        if(op == 1) {
            cnt ++, sum ++;
        }else if(op == -1) {
            if(cnt >= 2) cnt --;
            else ans = -1;
        }else {
            if(cnt >= 2)
                ql ++;
            else cnt ++, sum ++;
        }
    }
    if(ans == -1) {
        cout<< -1 <<endl;
        return;
    }else {
        if(cnt > ql) cnt -= ql;
        else sum += (ql - cnt - 1), cnt = 1;
        cout<< sum / __gcd(sum, cnt) << " " << cnt / __gcd(sum, cnt) <<endl;
    }
}

signed main() {
    std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
    cin>> t;
    while(t --) {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

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: 297ms
memory: 3620kb

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
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lines differ - expected: '3 2', found: '1 1'