QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89422 | #5420. Inscryption | IanD# | RE | 0ms | 0kb | C++14 | 836b | 2023-03-20 02:09:53 | 2023-03-20 02:09:56 |
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;
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