Submission #577552


Source Code Expand

Copy
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();
		}

		int base = 3;
		int[] b = new int[k + 1];
		b[0] = 1;
		for (int i = 0; i < k; i++) {
			b[i + 1] = b[i] * base;
		}

		int[] lsd = new int[k];
		for (int i = 0; i < b[k]; i++) {
			for (int j = 0; j < k; j++) {
				lsd[j] = i / b[j] % base + 1;
			}

			boolean flag = true;
			String[] s = new String[k];
			out:
			for (int j = 0; j < n; j++) {
				int from = 0;
				for (int l = 0; l < v[j].length; l++) {
					int d = v[j][l] - '1';
					if (w[j].length() < from + lsd[d]) {
						flag = false;
						break out;
					}
					String tmp = w[j].substring(from, from + lsd[d]);
					from += lsd[d];
					if (s[d] == null) {
						s[d] = tmp;
					} else {
						if (!tmp.equals(s[d])) {
							flag = false;
							break out;
						}
					}
				}
				if (from != w[j].length()) {
					flag = false;
					break out;
				}
			}

			if (flag) {
				for (String e : s) {
					System.out.println(e);
				}

				sc.close();
				return;
			}

		}

		sc.close();
	}
}

Submission Info

Submission Time
Task D - 語呂合わせ
User garnacha
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 1367 Byte
Status AC
Exec Time 585 ms
Memory 37852 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 40 / 40 60 / 60
Status
AC × 4
AC × 23
AC × 44
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 AC 585 ms 29240 KB
sample-02.txt AC 390 ms 28920 KB
sample-03.txt AC 401 ms 28928 KB
sample-04.txt AC 394 ms 29060 KB
subtask1-01.txt AC 399 ms 29144 KB
subtask1-02.txt AC 405 ms 29100 KB
subtask1-03.txt AC 400 ms 29112 KB
subtask1-04.txt AC 394 ms 29064 KB
subtask1-05.txt AC 395 ms 29028 KB
subtask1-06.txt AC 387 ms 29092 KB
subtask1-07.txt AC 403 ms 29124 KB
subtask1-08.txt AC 406 ms 29060 KB
subtask1-09.txt AC 409 ms 29000 KB
subtask1-10.txt AC 394 ms 29252 KB
subtask1-11.txt AC 390 ms 29092 KB
subtask1-12.txt AC 406 ms 29212 KB
subtask1-13.txt AC 412 ms 29128 KB
subtask1-14.txt AC 401 ms 29092 KB
subtask1-15.txt AC 420 ms 29132 KB
subtask1-16.txt AC 402 ms 29248 KB
subtask1-17.txt AC 410 ms 29140 KB
subtask1-18.txt AC 401 ms 29100 KB
subtask1-19.txt AC 420 ms 29040 KB
subtask1-20.txt AC 389 ms 29060 KB
subtask2-01.txt AC 431 ms 31000 KB
subtask2-02.txt AC 410 ms 30152 KB
subtask2-03.txt AC 446 ms 31856 KB
subtask2-04.txt AC 435 ms 34596 KB
subtask2-05.txt AC 436 ms 34168 KB
subtask2-06.txt AC 420 ms 31004 KB
subtask2-07.txt AC 453 ms 37852 KB
subtask2-08.txt AC 416 ms 29560 KB
subtask2-09.txt AC 433 ms 37420 KB
subtask2-10.txt AC 425 ms 36016 KB
subtask2-11.txt AC 425 ms 36156 KB
subtask2-12.txt AC 416 ms 32068 KB
subtask2-13.txt AC 422 ms 34240 KB
subtask2-14.txt AC 447 ms 33792 KB
subtask2-15.txt AC 436 ms 32504 KB
subtask2-16.txt AC 424 ms 29940 KB
subtask2-17.txt AC 381 ms 29132 KB
subtask2-18.txt AC 424 ms 35868 KB
subtask2-19.txt AC 424 ms 34924 KB
subtask2-20.txt AC 424 ms 35200 KB