QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625597 | #5420. Inscryption | travel | WA | 124ms | 5712kb | C++14 | 1.1kb | 2024-10-09 20:03:08 | 2024-10-09 20:03:10 |
Judging History
answer
//
// Created by travel on 2024/10/9.
//
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int a[1000009];
int n;
int back[1000009];
void solve()
{
int p = 1, q = 1, c = 0, t;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1;i <= n+1;i++) back[i] = 0;
for (int i = n; i >= 1; i--)
back[i] = back[i + 1] + a[i];
bool flag = 0;
for(int i = 1;i <= n;i++){
if(a[i] == 1)
p++,q++;
else if(a[i] == -1){
if(q > 1)
q--;
else {
flag = 1;
break;
}
}
else{
if(q + back[i] > 1){
if(q > 1)
q--;
else p++,q++;
}
else q++,p++;
}
}
if(flag) cout<<-1<<endl;
else cout << p/__gcd(p,q) <<' '<< q/__gcd(p,q) <<'\n';
}
signed main()
{
int turns;
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> turns;
while (turns--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5672kb
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: 124ms
memory: 5696kb
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 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