QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87164#5420. Inscryptionwhite2718WA 201ms3772kbC++141.4kb2023-03-11 20:44:272023-03-11 20:44:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-11 20:44:31]
  • 评测
  • 测评结果:WA
  • 用时:201ms
  • 内存:3772kb
  • [2023-03-11 20:44:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

inline int lcm(int n, int m) { return n * m / gcd(n, m); }
int t,n;
int a,b[1000010];
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        int cnt=1,flag=0,ccnt=0;
        b[1]=1;
        for(int i=0;i<n;i++){
            scanf("%d",&a);
            if(a==1){
                b[++cnt]=1;
            }
            if(a==-1){
                if(cnt>1){
                    b[1]+=b[cnt];
                    cnt--;
                }
                else{
                    if(ccnt){
                        b[1]+=1;
                        ccnt--;
                    }
                    else{
                        flag=1;
                    }
                }
            }
            if(a==0){
                ccnt++;
            }
        }
        if(flag){
            puts("-1");
            continue;
        }
        while(ccnt){
            if(cnt>1){
                b[1]+=b[cnt];
                cnt--;
            }
            else{
                b[++cnt]=1;
            }
            ccnt--;
        }
        int x=0,y=cnt;
        for(int i=1;i<=cnt;i++){
            x+=b[i];
        }
        int tmp=gcd(x,y);
        x/=tmp,y/=tmp;
        printf("%d %d\n",x,y);
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 201ms
memory: 3560kb

input:

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

result:

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