QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106413#5420. InscryptionwsygxljWA 234ms7840kbC++141.3kb2023-05-17 18:07:342023-05-17 18:07:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-17 18:07:39]
  • 评测
  • 测评结果:WA
  • 用时:234ms
  • 内存:7840kb
  • [2023-05-17 18:07:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int c1[1000006],c2[1000005],a[1000005];
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            c1[i]=c2[i]=0;
        }
        c1[n+1]=c2[n+1]=0;
        for(int i=n;i>0;i--)
        {
            if(a[i]==1)
            {
                c2[i]=c2[i+1];c1[i]=c1[i+1]+1;
            }
            else {
                    c2[i]=c2[i+1]+1;c1[i]=c1[i+1];
            }
           // cout<<c1[i]<<" "<<c2[i]<<endl;
        }
        int f=1;
        long long c=1,b=1;
        for(int i=1;i<=n;i++)
        {
            //cout<<c<<" "<<b<<" "<<c1[i]<<" "<<c2[i]<<endl;
            if(a[i]==1) c++,b++;
            else if(a[i]==-1)
            {
                if(b>=2) b--;
                else
                {
                    f=0;break;
                }
            }
            else
            {
                if(b+c1[i]>=c2[i]+1&&b>=2) b--;
                else c++,b++;
            }
        }
        if(f)
        {
            long long g=__gcd(c,b);
            printf("%lld %lld\n",c/g,b/g);
        }
        else printf("-1\n");
    }


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7840kb

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: 234ms
memory: 7664kb

input:

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

result:

wrong answer 71st lines differ - expected: '5 4', found: '-1'