QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743799 | #5420. Inscryption | HHS | WA | 367ms | 3812kb | C++14 | 1.3kb | 2024-11-13 20:03:09 | 2024-11-13 20:03:10 |
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++;
res1++;
res2++;
minn[i]=n+10;
}
else if(a[i]==-1)
{
s--;
cnt--;
res2--;
minn[i]=cnt;
}
else minn[i]=n+10,s++;
if(s<0)
{
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;
for(ll i=1;i<=point;i++)
{
if(a[i]==0)
{
if(sum+1<=minn[i])
{
res2--;
sum++;
cnt--;
}
else{
cnt++;
res1++;res2++;
sum--;
}
}
}
for(int 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();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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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