QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#250042 | #5420. Inscryption | cscnk52 | WA | 138ms | 3588kb | C++14 | 925b | 2023-11-12 20:45:15 | 2023-11-12 20:45:16 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e6+7;
int a[N];
int gcd(int x, int y) {
return x ? gcd(y % x, x) : y;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int flag=0;
int sum=1 , total=1;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]==1)
{
sum+=1;
total+=1;
}
else if(a[i]==0)
{
sum+=1;
a[i]=2;
total+=1;
}
else
{
sum-=1;
if(sum==0) flag=1;
}
}
if(flag==1)
{
cout<<-1<<endl;
continue;
}
int res=sum;
for(int i=n;i>=1;i--)
{
if(res>2&&a[i]==2)
{
res-=2;
sum-=2;
total-=1;
}else if(a[i]==1||a[i]==2)
{
res--;
}
}
cout << total / (gcd(total, sum)) << ' ' << sum / gcd(total, sum) << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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: 138ms
memory: 3432kb
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 1 0 1 -1 1 0 1 0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