QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#298382 | #6247. خوشحال پرانتزی | mahdimalverdi | WA | 90ms | 55664kb | Java11 | 1.2kb | 2024-01-06 05:41:46 | 2024-01-06 05:41:46 |
Judging History
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);
}
}
详细
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'