QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744018 | #5420. Inscryption | HHS | WA | 412ms | 3804kb | C++14 | 1.3kb | 2024-11-13 20:36:07 | 2024-11-13 20:36:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){
ll n;
cin>>n;
ll cnt=0;
ll res1=1,res2=1;
ll s=0;
vector<ll>a(n+10),minn(n+10);
int flag=1;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]==1)
{
s++;
cnt++;
minn[i]=n+10;
}
else if(a[i]==-1)
{
s--;
cnt--;
minn[i]=cnt;
}
else minn[i]=n+10,s++;
if(s<0&&flag)
{
cout<<-1<<endl;
flag=0;
}
}
if(!flag)
{
return ;
}
ll point =0;
for(ll i=n;i>=1;i--)if(!point&&a[i]==-1)point=i;
for(ll i=n-1;i>=1;i--)
{
minn[i]=min(minn[i],minn[i+1]);
}
ll sum=0;
// cout<<point<<endl;
cnt=0;
for(ll i=1;i<=point;i++)
{
if(a[i]==0)
{
if(sum+1<=minn[i])
{
res2--;
sum++;
cnt--;
}
else{
cnt++;
res1++;res2++;
sum--;
}
}
else if(a[i]==1)cnt++,res1++,res2++;
else cnt--,res2--;
}
//cout<<cnt<<endl;
for(ll i=point+1;i<=n;i++)
{
if(a[i]==0)
{
if(cnt>=1)
{
cnt--;
res2--;
}
else{
cnt++;
res1++;
res2++;
}
}
else if(a[i]==1)
{
cnt++;
res1++;
res2++;
}
}
cout<<res1/__gcd(res1,res2)<<" "<<res2/__gcd(res1,res2)<<endl;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll t;
cin >> t;
while(t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
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:
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