QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694846#5420. InscryptionTheLastHutuWA 0ms3544kbC++231.2kb2024-10-31 18:47:382024-10-31 18:47:38

Judging History

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

  • [2024-10-31 18:47:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3544kb
  • [2024-10-31 18:47:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
using pii = pair<int,int>;
const int inf = 1e10;
void solve(){
    int n;
    cin >> n;
    vector<int>v(n+1,0);
    for (int i = 1; i <= n; ++i) cin >> v[i];
    int sum = 1,cnt = 1,zero = 0;
    for (int i = 1; i <= n; ++i) {
        if (v[i] == 1)++sum, ++cnt;
        else if (v[i] == 0)++zero;
        else {
            if (cnt == 1) {
                if (zero)--zero, ++sum;
                else {
                    cout << -1 << endl;
                    return;
                }
            } else --cnt;
        }
    }
    auto Max = [&](pii a,pii b)->pii{
        if (a.first * b.second > b.first * a.second)return a;
        else return b;
    };
    pii res = {1,inf};
    for (int i = 0; i <=zero; ++i) {
        if (cnt + 2 * i - zero > 0){
            pii tmp = {sum + i,cnt + i - (zero - i)};
            res = Max(res,tmp);
        }
    }
    int g = __gcd(res.first,res.second);
    cout << res.first/g <<' '<<res.second<<endl;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _=1;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3544kb

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

result:

wrong answer 1st lines differ - expected: '3 2', found: '3 4'