QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691623#5420. InscryptionShawk#WA 143ms3820kbC++171.1kb2024-10-31 12:17:552024-10-31 12:17:58

Judging History

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

  • [2024-10-31 12:17:58]
  • 评测
  • 测评结果:WA
  • 用时:143ms
  • 内存:3820kb
  • [2024-10-31 12:17:55]
  • 提交

answer

#include <bits/stdc++.h>
#define test(x) cout << #x <<" = " << x << endl
#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;
    }
    int tt = min(sum-1, now);
    sum -= tt;
    now-=tt;
    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

1
6
1 1 1 0 0 0

4 1
*/

詳細信息

Test #1:

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

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: 143ms
memory: 3560kb

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

result:

wrong answer 28th lines differ - expected: '5 4', found: '2 1'