QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99697 | #5420. Inscryption | krito2023# | TL | 2ms | 3472kb | C++20 | 796b | 2023-04-23 15:12:23 | 2023-04-23 15:12:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n + 1),b(n+1);
int cnt1 = 0, cnt0 = 0;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
b[i]=a[i];
if(a[i]==0){
b[i]=1;
}
}
int ans=1,cnt=1,cha=1;
for(int i = 1; i <= n; i++){
if(b[i]==1){
ans++,cnt++;
cha++;
}
else{
cha--;
cnt--;
}
if(cnt<=0){
cout<<"-1\n";
return ;
}
}
for(int i=n;i;--i){
if(a[i]==0&&cha>2){
b[i] = -1;
cha-=2;
}
}
ans=1,cnt=1;
for(int i=1;i<=n;++i){
if(b[i]==1){
ans++;cnt++;
}
else{
cnt--;
}
}
int tmp = __gcd(ans, cnt);
ans /= tmp, cnt /= tmp;
cout << ans << " " << cnt << "\n";
}
int main() {
int t;
cin >> t;
while(t --) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3472kb
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 ...