QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733388 | #5420. Inscryption | wantsth | WA | 355ms | 3540kb | C++23 | 921b | 2024-11-10 18:33:26 | 2024-11-10 18:33:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin>>n;
vector<int>a(n+1);
int x=1;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int num=1;
int k=0;
for(int i=0;i<n;i++)
{
if(a[i]==1)
{
x+=1;
num+=1;
}
else if(a[i]==-1)
{
num-=1;
}
else
{
k+=1;
}
if(num==0)
{
if(k>0)
{
k-=1;
x+=1;
num+=1;
}
else
{
cout<<-1<<endl;
return;
}
}
}
// cout<<x<<" "<<num<<" "<<k<<endl;
if(k>0)
{
if(num>k)
{
x+=k;
num-=k;
}
else
{
int shu=num;
num=1;
k-=(shu-1);
if(k%2==0)
{
x+=k/2;
}
else
{
x+=k/2+1;
num+=1;
}
}
}
int gg=__gcd(x,num);
cout<<x/gg<<" "<<num/gg<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
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: 355ms
memory: 3532kb
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 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