QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691604#5420. InscryptionShawk#WA 147ms3772kbC++171.0kb2024-10-31 12:11:572024-10-31 12:11:59

Judging History

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

  • [2024-10-31 12:11:59]
  • 评测
  • 测评结果:WA
  • 用时:147ms
  • 内存:3772kb
  • [2024-10-31 12:11:57]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

void sol(){
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    int now = 0, sum = 1, ans = 1;
    for(int i = 1; i <= n; ++i)
        cin>>a[i];
    for(int i = 1; i <= n; ++i) {
        if(a[i] == 1)
            ++ans;
        if(a[i] == 0)
            ++now;
        else
            sum += a[i];
        // while(sum < 0 && now)
        if(sum > 0)
            continue;
        if(sum <= 0 && now == 0) {
            cout<<"-1\n";
            return;
        }
        ++sum;
        --now;
        ++ans;
    }
    sum += (now%2 == 1);
    ans +=(now + 1)/2;
    int x = ans, y = sum;
    x/=__gcd(ans, sum), y/= __gcd(ans, sum);
    cout<<x <<" "<< y <<endl;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--) {
        sol();
    }
    return 0;
}
/*
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
*/

详细

Test #1:

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

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: 147ms
memory: 3556kb

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
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
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'