QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233910 | #5108. Prehistoric Programs | shoja | WA | 685ms | 174100kb | Java8 | 1.5kb | 2023-11-01 08:18:53 | 2023-11-01 08:18:53 |
Judging History
answer
import java.util.*;
public class Main
{
public Main(){
Scanner input = new Scanner(System.in);
int n = Integer.parseInt(input.nextLine());
Parentheses[] p = new Parentheses[n];
String line;
int totSum = 0;
for(int i=0; i<n; i++){
line = input.nextLine();
int s=0,t=0,min=0;
for(int j=0; j<line.length(); j++){
char ch = line.charAt(j);
if(ch==')'){
s-=1;
t-=1;
if(s<min)
min=s;
}else if(ch=='('){
s+=1;
t+=1;
}
}
p[i] = new Parentheses (i+1, min, t);
totSum += t;
}
if(totSum != 0){
System.out.println("impossible");
System.exit(0);
}
Arrays.sort(p);
for(int i=0; i<n; i++){
System.out.println(p[i].index);
}
}
public static void main(String[] args){
new Main();
}
private class Parentheses implements Comparable<Parentheses> {
int start;
int total;
int index;
public Parentheses (int i, int s, int t){
index = i;
start = s;
total= t;
}
@Override
public int compareTo(Parentheses p){
return p.start - start;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 685ms
memory: 174100kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
1 2 5 7 8 9 10 11 12 13 14 16 19 23 27 28 29 30 32 34 35 37 38 42 43 44 54 55 58 59 61 65 69 70 72 76 77 79 80 87 91 92 93 94 95 96 97 99 103 112 116 117 118 120 122 125 126 127 128 129 130 131 133 135 136 143 146 147 148 149 150 151 154 161 162 163 164 165 166 169 172 175 176 177 178 179 181 182 18...
result:
ok good plan
Test #2:
score: 0
Accepted
time: 108ms
memory: 63360kb
input:
1000 ( ))(())) ((((())())))((())(()))( )( ) ))) ))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()()) )((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))( )))((( ( )))()()()))) ( (((())(((...
output:
1 3 10 12 13 14 17 18 20 22 30 31 33 35 36 39 45 54 58 60 62 64 65 66 75 77 80 83 84 85 88 89 90 92 97 98 101 104 106 110 112 115 122 123 125 126 127 128 131 134 135 136 143 147 162 164 166 168 171 177 178 179 181 182 188 189 190 197 198 206 208 209 212 213 214 215 216 217 221 223 228 229 239 242 24...
result:
ok good plan
Test #3:
score: 0
Accepted
time: 46ms
memory: 28096kb
input:
2 () ()
output:
1 2
result:
ok good plan
Test #4:
score: 0
Accepted
time: 34ms
memory: 28140kb
input:
2 (( ))
output:
1 2
result:
ok good plan
Test #5:
score: -100
Wrong Answer
time: 51ms
memory: 28188kb
input:
2 )( ()
output:
2 1
result:
wrong answer wrong plan (expected impossible)