QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#228676#5420. Inscryptionmobbb#WA 307ms3616kbC++171.4kb2023-10-28 13:57:242023-10-28 13:57:24

Judging History

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

  • [2023-10-28 13:57:24]
  • 评测
  • 测评结果:WA
  • 用时:307ms
  • 内存:3616kb
  • [2023-10-28 13:57:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve(){
    int n;cin >> n;
    vector<int> a(n + 1);
    for (int i = 1;i <= n;i++){
        cin >> a[i];
    }
    int cur = 1;
    int siz = 1;
    int zero = 0;
    for (int i = 1;i <= n;i++){
        cur += a[i] == 1;
        siz += a[i] == 1;
        siz -= a[i] == -1;
        zero += a[i] == 0;
        if (siz == 0){
            if (zero == 0){
                cout << -1 << endl;
                return;
            }else{
                zero--;
                cur++;
                siz++;
            }
        }
    }
    int r = -1;
    int p,q;
    for (int i = 0;i <= zero;i++){
        int cbin = zero - i;
        if (cbin >= siz + i){
            continue;
        }
        double rr = (double)1.0 * (cur + i) / (siz - cbin + i);
        if (r == -1 || (cur + i) * q > (siz - cbin + i) * p){
            r = rr;
            int d = gcd(cur + i,siz - cbin + i);
            int pp = (cur + i) / d;
            int qq = (siz - cbin + i) / d;
            p = pp,q = qq;
        }
    }
    if (r == -1){
        cout << -1 << endl;
    }else
        cout << p << " " << q << endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;cin >> T;
    while (T--){
        solve();
    }

    return 0;
}

详细

Test #1:

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

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: 307ms
memory: 3616kb

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'