QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#97578#5615. Two Charts Become OneNicolas125841TL 882ms117784kbJava111.6kb2023-04-17 11:17:422023-04-17 11:17:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-17 11:17:46]
  • 评测
  • 测评结果:TL
  • 用时:882ms
  • 内存:117784kb
  • [2023-04-17 11:17:42]
  • 提交

answer

import java.io.*;
import java.util.*;

public class tcbo {

	public static void main(String args[]) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		HashMap<Integer, TreeSet<Integer>> a = createTree(br);
		HashMap<Integer, TreeSet<Integer>> b = createTree(br);
		
		//System.out.println(a);
		//System.out.println(b);
		
		if(a.equals(b))
			pw.println("Yes");
		else
			pw.println("No");
		
		pw.close();
	}
	
	static HashMap<Integer, TreeSet<Integer>> createTree(BufferedReader br) throws IOException{
		Stack<Integer> stack = new Stack<Integer>();		
		HashMap<Integer, TreeSet<Integer>> tree = new HashMap<>();
		
		String[] line = br.readLine().split(" ");
		
		Queue<Character> clist = new LinkedList<Character>();
				
		for(String s : line)
			s.chars().forEach(c -> clist.add((char) c));		
				
		while(!clist.isEmpty()) {
			if(Character.isDigit(clist.peek())) {
				int num = clist.poll()-'0';
				
				while(!clist.isEmpty() && Character.isDigit(clist.peek())) {
					num *= 10;
					num += clist.poll()-'0';
				}
				
				if(!stack.isEmpty()) {
					tree.putIfAbsent(stack.peek(), new TreeSet<Integer>());
					tree.get(stack.peek()).add(num);
				}
				
				stack.push(num);
			}else {
				if(clist.poll().charValue() == ')')
					stack.pop();
			}
		}
		
		if(!stack.isEmpty()) {
			tree.put(-1, new TreeSet<Integer>());
			tree.get(-1).add(stack.pop());
		}		
		
		return tree;
	}
}

详细

Test #1:

score: 100
Accepted
time: 65ms
memory: 52692kb

input:

11 (10) (12 (13) (17) (28))
11 (12 (17) (28) (13)) (10)

output:

Yes

result:

ok single line: 'Yes'

Test #2:

score: 0
Accepted
time: 52ms
memory: 52480kb

input:

11 ( 10 ) ( 12 )
11(10(12))

output:

No

result:

ok single line: 'No'

Test #3:

score: 0
Accepted
time: 76ms
memory: 52764kb

input:

11 (10) (12)
11 (10) (13)

output:

No

result:

ok single line: 'No'

Test #4:

score: 0
Accepted
time: 729ms
memory: 96840kb

input:

289384 (694459 (751708 (887544 (519034 (207488 (373389 ) (912072 ) (191461 ) (91909 ) (5562 ) (705802 ) (469815 ) (726477 ) ) (204098 (530445 ) (655063 ) (156343 ) (980456 ) (186944 ) (198850 ) ) ) (502461 (427161 (615081 ) (801892 ) (594639 ) (786804 ) (811554 ) (810699 ) (935475 ) (717636 ) ) (537...

output:

No

result:

ok single line: 'No'

Test #5:

score: 0
Accepted
time: 430ms
memory: 76496kb

input:

289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 ) (5562 ) ) (705802 (469815 ) (726477 ) (204098 ) (530445 ) (655063 ) ) ) (156343 (980456 (186944 ) (198850 ) ) (502461 (427161 ) (615081 ) (801892 ) (594639 ) (786804 ) ) (811554 (810699 ) (935475 ) (717636 ) (537132 ) ) ...

output:

Yes

result:

ok single line: 'Yes'

Test #6:

score: 0
Accepted
time: 443ms
memory: 82980kb

input:

289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 ) (5562 ) ) (705802 (469815 ) (726477 ) (204098 ) (530445 ) (655063 ) ) ) (156343 (980456 (186944 ) (198850 ) ) (502461 (427161 ) (615081 ) (801892 ) (594639 ) (786804 ) ) (811554 (810699 ) (935475 ) (717636 ) (537132 ) ) ...

output:

No

result:

ok single line: 'No'

Test #7:

score: 0
Accepted
time: 435ms
memory: 79320kb

input:

289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 ) ) (705802 (469815 ) (726477 ) ) (204098 (530445 ) (655063 ) (156343 ) (980456 ) ) ) (186944 (198850 (502461 ) (427161 ) ) (615081 (801892 ) ) (594639 (786804 ) (811554 ) (810699 ) ) ) (935475 (717636 (537132 ) (678...

output:

Yes

result:

ok single line: 'Yes'

Test #8:

score: 0
Accepted
time: 401ms
memory: 76944kb

input:

289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 ) ) (705802 (469815 ) (726477 ) ) (204098 (530445 ) (655063 ) (156343 ) (980456 ) ) ) (186944 (198850 (502461 ) (427161 ) ) (615081 (801892 ) ) (594639 (786804 ) (811554 ) (810699 ) ) ) (935475 (717636 (537132 ) (678...

output:

No

result:

ok single line: 'No'

Test #9:

score: 0
Accepted
time: 378ms
memory: 69456kb

input:

289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 (705802 (469815 (726477 (204098 (530445 (655063 (156343 (980456 (186944 (198850 ) ) ) (502461 (427161 (615081 ) (801892 ) ) (594639 (786804 ) ) ) ) ) ) (811554 (810699 (935475 (717636 (537132 (678641 ) (777412 ) ) (6...

output:

Yes

result:

ok single line: 'Yes'

Test #10:

score: 0
Accepted
time: 349ms
memory: 70940kb

input:

289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 (705802 (469815 (726477 (204098 (530445 (655063 (156343 (980456 (186944 (198850 ) ) ) (502461 (427161 (615081 ) (801892 ) ) (594639 (786804 ) ) ) ) ) ) (811554 (810699 (935475 (717636 (537132 (678641 ) (777412 ) ) (6...

output:

No

result:

ok single line: 'No'

Test #11:

score: 0
Accepted
time: 50ms
memory: 52876kb

input:

10
10

output:

Yes

result:

ok single line: 'Yes'

Test #12:

score: 0
Accepted
time: 62ms
memory: 52592kb

input:

10
1

output:

No

result:

ok single line: 'No'

Test #13:

score: 0
Accepted
time: 882ms
memory: 117784kb

input:

289384 (638630 ) (239184 ) (765440 ) (646178 (372606 ) (910028 ) (190096 ) (91605 ) (5527 ) (705508 ) (469479 ) (726199 ) (201953 ) (529344 ) (653748 ) (154974 ) (979397 ) (186316 ) (197719 ) (501602 ) (426553 ) (613347 ) (801743 ) (593510 ) (786392 ) (809643 ) (810562 ) (934493 ) (717125 ) (535195 ...

output:

Yes

result:

ok single line: 'Yes'

Test #14:

score: -100
Time Limit Exceeded

input:

289384 (638630 ) (239184 ) (765440 ) (646178 (372606 ) (910028 ) (190096 ) (91605 ) (5527 ) (705508 ) (469479 ) (726199 ) (201953 ) (529344 ) (653748 ) (154974 ) (979397 ) (186316 ) (197719 ) (501602 ) (426553 ) (613347 ) (801743 ) (593510 ) (786392 ) (809643 ) (810562 ) (934493 ) (717125 ) (535195 ...

output:


result: