QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90636#5420. InscryptionSaanteyeRE 246ms3352kbC++141.5kb2023-03-24 14:21:112023-03-24 14:21:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-24 14:21:13]
  • 评测
  • 测评结果:RE
  • 用时:246ms
  • 内存:3352kb
  • [2023-03-24 14:21:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> f(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<int> s;
    queue<int> que0;
    int p = 1,q = 1;
    for(int i = 0; i < n; i++) {
        if(a[i] == 1)
            s.push_back(i);
        else if(a[i] == 0)
            que0.push(i);
        else if(a[i] == -1) {
            if(s.size()) {
                s.pop_back();
                p += 1;
            }
            else if(que0.size()){
                que0.pop();
                p += 1;
            }
            else {
                cout << "-1\n";
                return;
            }
        }
    }

    int v = 0;

    for(int i = 0; i < s.size(); i++) {
        if(que0.size()) {
            while(!que0.empty() && que0.front() < s[i]) {
                v++;
                que0.pop();
            }
            if(s[i] < que0.front()) {
                p += 1;
                que0.pop();
            }
            else {
                q+=1;p+=1;
            }
        }
        else {
            q+=1;p+=1;
        }
    }
    v += que0.size();

    p += v / 2;
    p += v % 2;
    q += v % 2;
    cout << p / __gcd(p,q) << ' ' << q / (__gcd(p,q)) << '\n';
}


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

    int t = 1;
    cin >> t;

    while(t--) solve();


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3352kb

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: 246ms
memory: 3300kb

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
0
1
1
1
1
1
-1
1
0
1
-1
1
-1
1
-1
1
-1
1
0
1
0
1
-1
1
0
1
-1
1
0
1
0
1
0
1
0
1
0
1
-1
1
1
1
0
1
0
1
1
1
0
1
-1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
...

output:

1 1
-1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
-1
-1
-1
1 1
1 1
-1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 ...

result:

ok 1000000 lines

Test #3:

score: -100
Runtime Error

input:

181249
6
1 0 -1 0 1 0
4
1 -1 -1 -1
8
-1 0 0 0 1 -1 1 1
3
0 1 0
6
1 0 -1 1 -1 0
4
1 -1 -1 -1
9
0 1 0 -1 -1 0 -1 0 1
1
-1
3
0 -1 1
5
0 0 1 -1 1
3
1 -1 0
6
-1 0 0 -1 0 1
8
1 -1 -1 -1 0 1 -1 0
2
0 0
3
-1 1 0
3
0 -1 -1
10
0 1 0 -1 1 1 0 -1 1 0
3
1 0 0
9
1 -1 1 -1 0 -1 0 0 0
3
0 1 0
3
-1 0 0
7
-1 0 -1 -1 ...

output:


result: