QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#110286 | #5420. Inscryption | zhuidao | WA | 219ms | 3540kb | C++20 | 1.7kb | 2023-06-01 14:05:14 | 2023-06-01 14:05:17 |
Judging History
answer
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>pi;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(int i=a;i<=n;i++)
#define ref(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"Yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define V vector<int>
#define all(v) v.begin(),v.end()
//ofstream fout("out.txt", ios::out);
//ifstream fin("in.txt", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------
//--------------------刘魔魔中魔--------------------
const int N=1e6+10;
int a[N],f[N],g[N];
int n;
void solve()
{
cin>>n;
fer(i,1,n)
{
cin>>a[i];
}
f[n+1]=g[n+1]=0;
for(int i=n;i>=1;i--)
{
int w=a[i];
if(!w)w++;
g[i]=max(g[i+1],0ll)+w;
f[i]=max(f[i+1],g[i]);
}
int sum=1,cnt=1;
for(int i=1;i<=n;i++)
{
if(a[i]==1)
{
sum++;cnt++;
}
else if(a[i]==-1)
{
if(cnt<=1)re(-1);
cnt--;
}
else
{
if(cnt-1-f[i+1]>=1)
{
cnt--;
}
else
{
sum++;cnt++;
}
}
}
int gd=gcd(sum,cnt);
cout<<sum/gd<<' '<<cnt/gd<<endl;
}
signed main()
{
ac;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
6 7 1 1 1 -1 1 1 -1 4 1 0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