Submission #576375


Source Code Expand

Copy
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		int n = sc.nextInt();
		char[][] v = new char[n][];
		String[] w = new String[n];
		for (int i = 0; i < n; i++) {
			v[i] = sc.next().toCharArray();
			w[i] = sc.next();
		}

		if (k > 3) {
			for (int i = 0; i < k; i++) {
				System.out.println("0");
			}

			sc.close();
			return;
		}

		String[] s = {"a", "aa", "aaa", "b", "bb", "bbb", "c", "cc", "ccc"};

		Queue<Integer> qk = new ArrayDeque<Integer>();
		Queue<Queue<Integer>> qs = new ArrayDeque<Queue<Integer>>();
		qk.add(0);
		while (!qk.isEmpty()) {
			int e = qk.remove();

			if (e == k) {
				boolean flag = true;
				Queue<Integer> qtmp = qs.remove();
				Integer[] itmp = new Integer[0];
				itmp = qtmp.toArray(itmp);
				for (int i = 0; i < n; i++) {
					String tmp = "";
					for (int j = 0; j < v[i].length; j++) {
						tmp += s[itmp[v[i][j] - '1']];
					}
					if (!tmp.equals(w[i])) {
						flag = false;
						break;
					}
				}
				if (flag) {
					for (int ee : itmp) {
						System.out.println(s[ee]);
					}

					sc.close();
					return;
				}
			} else {
				Queue<Integer> tmp;
				if (e == 0) {
					tmp = new ArrayDeque<Integer>();
				} else {
					tmp = qs.remove();
				}
				for (int i = 0; i < s.length; i++) {
					Queue<Integer> ttmp = new ArrayDeque<Integer>(tmp);
					ttmp.add(i);
					qs.add(ttmp);
					qk.add(e + 1);
				}
			}
		}

		sc.close();
	}
}

Submission Info

Submission Time
Task D - 語呂合わせ
User garnacha
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1640 Byte
Status WA
Exec Time 731 ms
Memory 30516 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 0 / 40 0 / 60
Status
AC × 1
WA × 3
AC × 6
WA × 17
AC × 6
WA × 38
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Subtask1 sample-02.txt, sample-03.txt, sample-04.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt
Subtask2 sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt, subtask2-16.txt, subtask2-17.txt, subtask2-18.txt, subtask2-19.txt, subtask2-20.txt
Case Name Status Exec Time Memory
sample-01.txt WA 529 ms 29360 KB
sample-02.txt AC 492 ms 29120 KB
sample-03.txt WA 408 ms 29096 KB
sample-04.txt WA 371 ms 29104 KB
subtask1-01.txt WA 389 ms 29476 KB
subtask1-02.txt WA 385 ms 29336 KB
subtask1-03.txt WA 404 ms 30516 KB
subtask1-04.txt WA 390 ms 30248 KB
subtask1-05.txt AC 395 ms 29864 KB
subtask1-06.txt WA 394 ms 29356 KB
subtask1-07.txt WA 403 ms 29564 KB
subtask1-08.txt WA 418 ms 30252 KB
subtask1-09.txt AC 420 ms 29984 KB
subtask1-10.txt WA 395 ms 30132 KB
subtask1-11.txt WA 400 ms 30384 KB
subtask1-12.txt WA 451 ms 29728 KB
subtask1-13.txt WA 413 ms 30376 KB
subtask1-14.txt WA 432 ms 29996 KB
subtask1-15.txt AC 528 ms 29544 KB
subtask1-16.txt WA 557 ms 30472 KB
subtask1-17.txt AC 731 ms 29728 KB
subtask1-18.txt WA 613 ms 29480 KB
subtask1-19.txt WA 464 ms 29804 KB
subtask1-20.txt AC 410 ms 29288 KB
subtask2-01.txt WA 495 ms 29092 KB
subtask2-02.txt WA 423 ms 29112 KB
subtask2-03.txt WA 411 ms 29108 KB
subtask2-04.txt WA 462 ms 29088 KB
subtask2-05.txt WA 383 ms 29092 KB
subtask2-06.txt WA 385 ms 29128 KB
subtask2-07.txt WA 413 ms 29160 KB
subtask2-08.txt WA 454 ms 29088 KB
subtask2-09.txt WA 418 ms 29076 KB
subtask2-10.txt WA 384 ms 29168 KB
subtask2-11.txt WA 386 ms 29076 KB
subtask2-12.txt WA 397 ms 29036 KB
subtask2-13.txt WA 382 ms 29132 KB
subtask2-14.txt WA 382 ms 29120 KB
subtask2-15.txt WA 410 ms 29056 KB
subtask2-16.txt WA 397 ms 29108 KB
subtask2-17.txt WA 386 ms 29220 KB
subtask2-18.txt WA 423 ms 29000 KB
subtask2-19.txt WA 508 ms 29208 KB
subtask2-20.txt WA 521 ms 29216 KB