QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106423#5420. InscryptionwsygxljWA 3ms9776kbC++141.3kb2023-05-17 18:26:032023-05-17 18:26:06

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:26:06]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9776kb
  • [2023-05-17 18:26:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int c1[1000006],c2[1000005],a[1000005],cs[1000006];
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,cs[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];
            }

            if(a[i]==-1) cs[i]=cs[i+1]+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>=cs[i+1]+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: 0
Wrong Answer
time: 3ms
memory: 9776kb

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
1 1
-1

result:

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