QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#233916#5108. Prehistoric ProgramsshojaWA 566ms174660kbJava81.7kb2023-11-01 08:29:062023-11-01 08:29:06

Judging History

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

  • [2023-11-01 08:29:06]
  • 评测
  • 测评结果:WA
  • 用时:566ms
  • 内存:174660kb
  • [2023-11-01 08:29:06]
  • 提交

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