QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89421#5420. InscryptionIanD#RE 0ms0kbC++14763b2023-03-20 02:01:262023-03-20 02:01:30

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

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;
    for(cin>>T;T--;){
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>a[i];
        check();
    }
    return 0;
}

詳細信息

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: