QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89422#5420. InscryptionIanD#RE 0ms0kbC++14836b2023-03-20 02:09:532023-03-20 02:09:56

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-20 02:09:56]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-03-20 02:09:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = int(1e6) + 9;
int a[N];
int n;

bool check() {
    int flag=1;
    int p=1, q=1, cnt=0;
    for(int i=0;i<n;i++) {
        if (a[i]==1) {++p; ++q;}
        else if (a[i]==-1) {
            if(q>1) {--q;}
            else if(cnt) {--cnt; ++p; ++q;}
            else {flag=0;break;}
        } else {
            if (q<=1) {++p;++q;}
            else {--q;++cnt;}
        }
    }
    if(!flag) cout<<-1<<endl;
    else{
        int d = __gcd(p,q);
        p/=d; q/=d;
        cout<<p<<" "<<q<<endl;
    }
}

int main(){
    int T;
    while(cin>>T){
        while(T--){
            memset(a,0,sizeof(a));
            cin>>n;
            for(int i=0;i<n;i++)
                cin>>a[i];
            check();
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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

result: