QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298382#6247. خوشحال پرانتزیmahdimalverdiWA 90ms55664kbJava111.2kb2024-01-06 05:41:462024-01-06 05:41:46

Judging History

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

  • [2024-01-06 05:41:46]
  • 评测
  • 测评结果:WA
  • 用时:90ms
  • 内存:55664kb
  • [2024-01-06 05:41:46]
  • 提交

answer


import java.util.Scanner;

class Codechef {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String str = sc.nextLine();

        int counter = 0;
        int firstOpen = Integer.MAX_VALUE;
        int firstClose = Integer.MAX_VALUE;

        for(int i=0;i<n;i++){
            if(str.charAt(i) == '('){
                counter++;
                firstOpen = Math.min(firstOpen, i);
            }
            if(str.charAt(i) == ')'){
                counter--;
                firstClose = Math.min(firstClose, i);
            }
        }

        if(counter != 0){
            System.out.println(0);
            return;
        }

        int result = 0;
        for(int i=0;i<n;i++){
            if(str.charAt((i+firstOpen)%n) == '('){
                counter++;
            }
            if(str.charAt((i+firstOpen)%n) == ')'){
                counter--;
            }
            if(counter == 0){
                result++;
            }
        }

            System.out.println(result);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 69ms
memory: 53492kb

input:

6
))()((

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 90ms
memory: 55664kb

input:

6
())(()

output:

3

result:

wrong answer 1st lines differ - expected: '1', found: '3'