QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89421 | #5420. Inscryption | IanD# | RE | 0ms | 0kb | C++14 | 763b | 2023-03-20 02:01:26 | 2023-03-20 02:01:30 |
Judging History
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;
}
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