QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#554960#5420. InscryptionHTensor#WA 0ms3528kbC++171.4kb2024-09-09 18:22:312024-09-09 18:22:31

Judging History

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

  • [2024-09-09 18:22:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3528kb
  • [2024-09-09 18:22:31]
  • 提交

answer

#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x  << ": " << x << "\n"
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
const int inf = 0x3f3f3f3f3f3f3f3fLL;

void solve() {
    int n; cin >> n;
    vector<int> a(n + 1);
    int fz = 1, fm = 1;

    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int cnt = 0;
    auto minus = [&]() {
        --fm;
        if(!fm) {
            if(!cnt) return false;
            else {
                --cnt;
                ++fm; ++fz, ++fm;
            }
        }
        return true;
    };

    int ans = 1;
    for(int i = 1; i <= n; i++) {
        if(a[i] == 1) fz++, fm++;
        else if(!a[i]) {
            if(!minus()) {
                ++fm, ++fz, ++fm;
                ++cnt;
            }
        } else {
            if(!minus()) {
                ans = 0; break;
            }
        }
    }

    if(!ans) {
        cout << -1 << "\n";
    } else {
        int gcdv = __gcd(fz, fm);
        cout << fz / gcdv << " " << fm / gcdv << "\n";
    }
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int T; cin >> T;
    while(T--) solve();
    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
4
1 0 -1 0

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

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