QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#623549 | #5420. Inscryption | Soestx | WA | 323ms | 3704kb | C++23 | 973b | 2024-10-09 13:00:45 | 2024-10-09 13:00:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int,int>
#define fi first
#define se second
typedef long long LL;
typedef unsigned long long ull;
int n,m,k;
const int N=1e3+10,M=1e5+10,mod=45989;
int num[N];
int res,cnt;
pll cmp(pll p1,pll p2)
{
return p1.fi*p2.se>p2.fi*p1.se?p1:p2;
}
void solve() {
cin>>n;
m=0;
int a1=1,a2=1;
bool flag=1;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(x==1) a1++,a2++;
if(x==-1)
{
if(a2>1) a2--;
else if(m) m--,a1++;
else flag=0;
}
if(x==0) m++;
}
if(!flag)
{
cout<<"-1"<<endl;
return;
}
pll res={a1,a2};
for(int i=1;i<=m;i++)
{
if(a2+i<=m-i) break;
res=cmp(res,{a1+i,a2+i-(m-i)});
}
int t=__gcd(res.fi,res.se);
cout<<res.fi/t<<" "<<res.se/t<<endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3704kb
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
time: 323ms
memory: 3596kb
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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