Submission #63009370
Source Code Expand
Copy
import java.util.Scanner;import java.util.Stack;public class Main{public static void main(String[] args) {Scanner in = new Scanner(System.in);String S = in.next();Stack<Character> stack = new Stack<>();for (char c : S.toCharArray()) {if (c == '(' || c == '[' || c == '<') {stack.push(c);} else {if (stack.isEmpty()) {System.out.println("No");return;}char top = stack.pop();
import java.util.Scanner; import java.util.Stack; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); String S = in.next(); Stack<Character> stack = new Stack<>(); for (char c : S.toCharArray()) { if (c == '(' || c == '[' || c == '<') { stack.push(c); } else { if (stack.isEmpty()) { System.out.println("No"); return; } char top = stack.pop(); if ((c == ')' && top != '(') || (c == ']' && top != '[') || (c == '>' && top != '<')) { System.out.println("No"); return; } } } System.out.println(stack.isEmpty() ? "Yes" : "No"); } }
Submission Info
Submission Time | |
---|---|
Task | D - Colorful Bracket Sequence |
User | pitch_black |
Language | Java (OpenJDK 17) |
Score | 400 |
Code Size | 926 Byte |
Status | AC |
Exec Time | 170 ms |
Memory | 42876 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt, example_02.txt |
All | example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 69 ms | 37748 KB |
example_01.txt | AC | 69 ms | 37756 KB |
example_02.txt | AC | 69 ms | 37728 KB |
hand_00.txt | AC | 164 ms | 42672 KB |
hand_01.txt | AC | 165 ms | 41876 KB |
hand_02.txt | AC | 161 ms | 42876 KB |
hand_03.txt | AC | 71 ms | 37668 KB |
hand_04.txt | AC | 160 ms | 42520 KB |
hand_05.txt | AC | 71 ms | 37824 KB |
hand_06.txt | AC | 71 ms | 38000 KB |
random_00.txt | AC | 140 ms | 42120 KB |
random_01.txt | AC | 164 ms | 42812 KB |
random_02.txt | AC | 168 ms | 42560 KB |
random_03.txt | AC | 161 ms | 42240 KB |
random_04.txt | AC | 143 ms | 42444 KB |
random_05.txt | AC | 165 ms | 42096 KB |
random_06.txt | AC | 117 ms | 41072 KB |
random_07.txt | AC | 145 ms | 41816 KB |
random_08.txt | AC | 158 ms | 42072 KB |
random_09.txt | AC | 165 ms | 42644 KB |
random_10.txt | AC | 158 ms | 41408 KB |
random_11.txt | AC | 154 ms | 41972 KB |
random_12.txt | AC | 153 ms | 42024 KB |
random_13.txt | AC | 150 ms | 41376 KB |
random_14.txt | AC | 161 ms | 41948 KB |
random_15.txt | AC | 156 ms | 41340 KB |
random_16.txt | AC | 157 ms | 41656 KB |
random_17.txt | AC | 141 ms | 41100 KB |
random_18.txt | AC | 154 ms | 41460 KB |
random_19.txt | AC | 139 ms | 41264 KB |
random_20.txt | AC | 162 ms | 41500 KB |
random_21.txt | AC | 162 ms | 41932 KB |
random_22.txt | AC | 154 ms | 41368 KB |
random_23.txt | AC | 159 ms | 41748 KB |
random_24.txt | AC | 156 ms | 42100 KB |
random_25.txt | AC | 150 ms | 41200 KB |
random_26.txt | AC | 162 ms | 42012 KB |
random_27.txt | AC | 170 ms | 41596 KB |
random_28.txt | AC | 166 ms | 41608 KB |
random_29.txt | AC | 158 ms | 41540 KB |