結果

問題 No.2256 Step by Step
ユーザー CuriousFairy315CuriousFairy315
提出日時 2023-03-24 23:07:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 3,153 bytes
コンパイル時間 5,208 ms
コンパイル使用メモリ 77,516 KB
実行使用メモリ 57,808 KB
最終ジャッジ日時 2023-10-18 21:28:45
合計ジャッジ時間 8,555 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,688 KB
testcase_01 AC 133 ms
57,616 KB
testcase_02 AC 170 ms
57,648 KB
testcase_03 AC 170 ms
57,664 KB
testcase_04 AC 169 ms
57,272 KB
testcase_05 AC 167 ms
57,408 KB
testcase_06 AC 135 ms
57,672 KB
testcase_07 AC 132 ms
57,620 KB
testcase_08 AC 133 ms
57,808 KB
testcase_09 AC 132 ms
57,620 KB
testcase_10 AC 129 ms
57,512 KB
testcase_11 AC 119 ms
56,264 KB
testcase_12 AC 136 ms
56,136 KB
testcase_13 AC 142 ms
57,520 KB
testcase_14 AC 142 ms
57,612 KB
testcase_15 AC 141 ms
57,500 KB
testcase_16 AC 145 ms
57,564 KB
testcase_17 AC 143 ms
57,512 KB
testcase_18 AC 170 ms
57,620 KB
testcase_19 AC 143 ms
55,628 KB
testcase_20 AC 143 ms
57,684 KB
testcase_21 AC 143 ms
57,672 KB
testcase_22 AC 140 ms
57,244 KB
testcase_23 AC 128 ms
56,152 KB
testcase_24 AC 130 ms
56,260 KB
testcase_25 AC 144 ms
57,584 KB
testcase_26 AC 141 ms
55,576 KB
testcase_27 AC 140 ms
57,624 KB
testcase_28 AC 132 ms
57,616 KB
testcase_29 AC 147 ms
57,552 KB
testcase_30 AC 144 ms
57,772 KB
testcase_31 AC 144 ms
57,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import static java.lang.System.err;

public class Main {
	public static void main(String[] args) {
		java.io.PrintWriter out = new java.io.PrintWriter(System.out);
		new Main(out);
		out.flush();
		err.flush();
	}

	/*
	 * 考察
	 * 連結パーツを作りたい
	 *
	 * 124
	 * 03x
	 * 03x
	 * 011
	 * 232
	 * 44x
	 * を始点パーツ
	 * x13
	 * 02x
	 * 12x
	 * x00
	 * x21
	 * 33x
	 * を接続パーツ
	 * x24
	 * 013
	 * 213
	 * x00
	 * x12
	 * 443
	 * を終点パーツとすると、5+2xは作れる
	 * 3665
	 * 244x
	 * 211x
	 * 1000
	 * 2334
	 * 455x
	 * で6+2xも作れる
	 * あ、勝ちました
	 * 1だと100011で良い、2は不可能が示せるので終了
	 */
	public Main(java.io.PrintWriter out) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int N = sc.nextInt();
			int[][] joint = { { -1, 1, 3 }, { 0, 2, -1 }, { 1, 2, -1 }, { -1, 0, 0 }, { -1, 2, 1 }, { 3, 3, -1 } };
			int[][] last = { { -1, 2, 4 }, { 0, 1, 3 }, { 2, 1, 3 }, { -1, 0, 0 }, { -1, 1, 2 }, { 4, 4, 3 } };
			if (N == 1) {
				out.println("0\n1\n1\n1\n0\n0");
			} else if (N == 2) {
				out.println(-1);
			} else if (N % 2 == 1) {
				int[][] first = { { 1, 2, 4 }, { 0, 3, -1 }, { 0, 3, -1 }, { 0, 1, 1 }, { 2, 3, 2 }, { 4, 4, -1 } };
				if (N == 3) {
					for (int[] i : first) {
						for (int j : i) {
							if (j == -1) j = 9;
							out.print(j);
						}
						out.println();
					}
					return;
				}
				int[][] ans = new int[6][N];
				int line = 0, add = 0;
				for (int y = 0;y < 6;++ y) {
					for (int x = 0;x < 3;++ x) {
						if (first[y][x] != -1) ans[y][x + line] = first[y][x];
					}
				}
				line += 2;
				add += 5;
				while(line + 3 != N) {
					for (int y = 0;y < 6;++ y) {
						for (int x = 0;x < 3;++ x) {
							if (joint[y][x] != -1) ans[y][x + line] = (joint[y][x] + add) % 10;
						}
					}
					line += 2;
					add += 5;
				}
				for (int y = 0;y < 6;++ y) {
					for (int x = 0;x < 3;++ x) {
						if (last[y][x] != -1) ans[y][x + line] = (last[y][x] + add) % 10;
					}
				}
				for (int[] i : ans) {
					for (int j : i) out.print(j);
					out.println();
				}
				return;
			} else {
				int[][] first = {{3, 6, 6, 5}, {2, 4, 4, -1}, {2, 1, 1, -1}, {1, 0, 0, 0}, {2, 3, 3, 4}, {6, 5, 5, -1}};
				if (N == 4) {
					for (int[] i : first) {
						for (int j : i) {
							if (j == -1) j = 9;
							out.print(j);
						}
						out.println();
					}
					return;
				}
				int[][] ans = new int[6][N];
				int line = 0, add = 0;
				for (int y = 0;y < 6;++ y) {
					for (int x = 0;x < 4;++ x) {
						if (first[y][x] != -1) ans[y][x + line] = first[y][x];
					}
				}
				line += 3;
				add += 7;
				while(line + 3 != N) {
					for (int y = 0;y < 6;++ y) {
						for (int x = 0;x < 3;++ x) {
							if (joint[y][x] != -1) ans[y][x + line] = (joint[y][x] + add) % 10;
						}
					}
					line += 2;
					add += 5;
				}
				for (int y = 0;y < 6;++ y) {
					for (int x = 0;x < 3;++ x) {
						if (last[y][x] != -1) ans[y][x + line] = (last[y][x] + add) % 10;
					}
				}
				for (int[] i : ans) {
					for (int j : i) out.print(j);
					out.println();
				}
				return;
			}
		}
	}
}
0