QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#233916 | #5108. Prehistoric Programs | shoja | WA | 566ms | 174660kb | Java8 | 1.7kb | 2023-11-01 08:29:06 | 2023-11-01 08:29:06 |
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);
int s=0, t=0;
for(int i=0; i<n; i++){
s = t + p[i].start;
if(s<0){
System.out.println("impossible");
System.exit(0);
}
t += p[i].total;
}
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;
}
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 566ms
memory: 174660kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
impossible
result:
wrong answer you didn't find a solution but jury did