QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#124731 | #5420. Inscryption | chinguun_0301# | TL | 1ms | 3404kb | C++14 | 1.2kb | 2023-07-15 14:57:34 | 2023-07-15 14:57:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, a[1000006];
void solve(){
cin >> n;
int sum = 0, b = 0;
int ttl1 = 0, ttl0 = 0, ttlm1 = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] == 1) ttl1++;
if(a[i] == -1) ttlm1++;
if(a[i] == 0) ttl0++;
if(a[i] == -1) sum--;
else sum++;
if(sum < 0) b = 1;
}
if(b == 1){
cout << -1 << "\n";
return;
}
int ttl = ttl0 + ttlm1 - ttl1;
if(ttl % 2 == 0) ttl = ttl / 2;
else ttl = ttl / 2 + 1;
int s1 = 1, s2 = 1;
// cout << "chinguun " << ttl << '\n';
for(int i = 0; i < n; i++){
if(a[i] == 1){
s1++;
s2++;
}
if(a[i] == -1){
s2--;
}
if(a[i] == 0){
if(ttl > 0){
s1++;
s2++;
ttl--;
}
else{
s2--;
}
}
}
int a = __gcd(s1, s2);
cout << s1 / a << ' ' << s2 / a << "\n";
}
int main(){
int t;
cin >> t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3404kb
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: -100
Time Limit Exceeded
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 1 0 1 0 1 0 1 0 1 -1 1 1 1 0 1 0 1 1 1 0 1 -1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 ...
output:
1 1 -1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 -1 -1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 -1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 ...