Submission #577083


Source Code Expand

Copy
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
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"};
		String[] s = {"a", "b", "c",
				"aa", "ab", "ac", "ba", "bb", "bc", "ca", "cb", "cc",
				"aaa", "aab", "aac", "aba", "abb", "abc", "aca", "acb", "acc",
				"baa", "bab", "bac", "bba", "bbb", "bbc", "bca", "bcb", "bcc",
				"caa", "cab", "cac", "cba", "cbb", "cbc", "cca", "ccb", "ccc",
		};

		Queue<List<Integer>> qs = new ArrayDeque<List<Integer>>();
		qs.add(new ArrayList<Integer>());
		while (!qs.isEmpty()) {
			List<Integer> e = qs.remove();

			if (e.size() == k) {
				boolean flag = true;
				for (int i = 0; i < n; i++) {
					String tmp = "";
					for (int j = 0; j < v[i].length; j++) {
						tmp += s[e.get(v[i][j] - '1')];
					}
					if (!tmp.equals(w[i])) {
						flag = false;
						break;
					}
				}
				if (flag) {
					for (int ee : e) {
						System.out.println(s[ee]);
					}

					sc.close();
					return;
				}
			} else {
				for (int i = 0; i < s.length; i++) {
					List<Integer> ltmp = new ArrayList<Integer>(e);
					ltmp.add(i);
					qs.add(ltmp);
				}
			}
		}

		sc.close();
	}
}

Submission Info

Submission Time
Task D - 語呂合わせ
User garnacha
Language Java8 (OpenJDK 1.8.0)
Score 40
Code Size 1718 Byte
Status WA
Exec Time 518 ms
Memory 42892 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 40 / 40 0 / 60
Status
AC × 3
WA × 1
AC × 23
AC × 23
WA × 21
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 341 ms 28936 KB
sample-02.txt AC 472 ms 35076 KB
sample-03.txt AC 371 ms 29620 KB
sample-04.txt AC 355 ms 29304 KB
subtask1-01.txt AC 447 ms 40832 KB
subtask1-02.txt AC 435 ms 40940 KB
subtask1-03.txt AC 487 ms 42872 KB
subtask1-04.txt AC 506 ms 42800 KB
subtask1-05.txt AC 440 ms 41344 KB
subtask1-06.txt AC 406 ms 35080 KB
subtask1-07.txt AC 441 ms 41184 KB
subtask1-08.txt AC 449 ms 41584 KB
subtask1-09.txt AC 450 ms 41384 KB
subtask1-10.txt AC 456 ms 41516 KB
subtask1-11.txt AC 500 ms 42832 KB
subtask1-12.txt AC 456 ms 41528 KB
subtask1-13.txt AC 504 ms 42888 KB
subtask1-14.txt AC 491 ms 42340 KB
subtask1-15.txt AC 440 ms 40992 KB
subtask1-16.txt AC 503 ms 42892 KB
subtask1-17.txt AC 442 ms 41264 KB
subtask1-18.txt AC 414 ms 35276 KB
subtask1-19.txt AC 518 ms 42204 KB
subtask1-20.txt AC 407 ms 35012 KB
subtask2-01.txt WA 351 ms 29024 KB
subtask2-02.txt WA 364 ms 29072 KB
subtask2-03.txt WA 368 ms 29124 KB
subtask2-04.txt WA 359 ms 29104 KB
subtask2-05.txt WA 339 ms 29164 KB
subtask2-06.txt WA 338 ms 29128 KB
subtask2-07.txt WA 353 ms 29200 KB
subtask2-08.txt WA 361 ms 29164 KB
subtask2-09.txt WA 359 ms 29168 KB
subtask2-10.txt WA 352 ms 29108 KB
subtask2-11.txt WA 344 ms 29100 KB
subtask2-12.txt WA 357 ms 29160 KB
subtask2-13.txt WA 339 ms 29168 KB
subtask2-14.txt WA 338 ms 29180 KB
subtask2-15.txt WA 346 ms 29132 KB
subtask2-16.txt WA 340 ms 29116 KB
subtask2-17.txt WA 341 ms 29068 KB
subtask2-18.txt WA 345 ms 29124 KB
subtask2-19.txt WA 362 ms 29200 KB
subtask2-20.txt WA 351 ms 29180 KB