QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#176261#5420. InscryptionZhou_JKWA 142ms6024kbC++231.1kb2023-09-11 13:53:262023-09-11 13:53:27

Judging History

你现在查看的是最新测评结果

  • [2023-09-11 13:53:27]
  • 评测
  • 测评结果:WA
  • 用时:142ms
  • 内存:6024kb
  • [2023-09-11 13:53:26]
  • 提交

answer

#include<iostream>
#include<cstdio>
using namespace std;
const int N=1000005;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int n;
int a[N];
int s[N];
int suf[N];
void solve()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        if(a[i]==-1) s[i]=s[i-1]-1;
        else s[i]=s[i-1]+1;
    suf[n+1]=suf[n]=s[n];
    for(int i=n-1;i>=1;i--)
        suf[i]=min(suf[i+1],s[i]);
//    for(int i=1;i<=n;i++)
//        cerr<<s[i]<<" ";cerr<<"\n";
    int tot=1,sum=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==1) tot++,sum++;
        else if(a[i]==-1)
        {
            if(tot>=2) tot--;
            else
            {
                printf("-1\n");
                return;
            }
        }
        else
        {
//            cerr<<"now"<<i<<" "<<suf[i+1]-s[i]<<"\n";
            if(tot-1<=-(suf[i+1]-s[i])) sum++,tot++;
            else tot--;
        }
    }
    int g=gcd(tot,sum);
    tot/=g,sum/=g;
    printf("%d %d\n",sum,tot);
    return;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 6016kb

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: 142ms
memory: 6024kb

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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
-1
1 1
-1
2 1
1 1
-1
1 1
-1
1 1
3 2
-1
-1
-1
-1
3 2
5 2
1 1
-1
3 1
-1
-1
1 1
-1
6 1
3 2
-1
3 2
4 3
2 1
-1
5 3
3 1
6 1
-1
2 1
5 4
-1
1 1
-1
3 1
-1
-1
5 3
1 1
2 1
5 2
-1
3 1
4 3...

result:

wrong answer 28th lines differ - expected: '5 4', found: '2 1'