結果
問題 | No.362 門松ナンバー |
ユーザー | Grenache |
提出日時 | 2016-08-04 23:24:45 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 167 ms / 3,000 ms |
コード長 | 3,187 bytes |
コンパイル時間 | 4,297 ms |
コンパイル使用メモリ | 82,120 KB |
実行使用メモリ | 43,036 KB |
最終ジャッジ日時 | 2024-11-07 00:09:08 |
合計ジャッジ時間 | 8,480 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 137 ms
41,384 KB |
testcase_01 | AC | 133 ms
40,544 KB |
testcase_02 | AC | 134 ms
40,480 KB |
testcase_03 | AC | 130 ms
40,508 KB |
testcase_04 | AC | 131 ms
41,148 KB |
testcase_05 | AC | 162 ms
41,800 KB |
testcase_06 | AC | 162 ms
41,796 KB |
testcase_07 | AC | 160 ms
41,460 KB |
testcase_08 | AC | 158 ms
42,948 KB |
testcase_09 | AC | 157 ms
41,424 KB |
testcase_10 | AC | 164 ms
42,108 KB |
testcase_11 | AC | 162 ms
41,836 KB |
testcase_12 | AC | 164 ms
41,744 KB |
testcase_13 | AC | 163 ms
41,872 KB |
testcase_14 | AC | 161 ms
43,036 KB |
testcase_15 | AC | 163 ms
41,672 KB |
testcase_16 | AC | 161 ms
42,448 KB |
testcase_17 | AC | 165 ms
42,564 KB |
testcase_18 | AC | 167 ms
42,436 KB |
testcase_19 | AC | 134 ms
40,940 KB |
testcase_20 | AC | 158 ms
41,956 KB |
testcase_21 | AC | 132 ms
40,560 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder362 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int t = sc.nextInt(); long[][] dp = new long[14][100]; Arrays.fill(dp[0], 1L); for (int i = 1; i < 14; i++) { for (int k = 0; k < 100; k++) { for (int l = 0; l < 100; l++) { if (isKado(k, l)) { dp[i][k] += dp[i - 1][l]; } } } } for (int tcase = 0; tcase < t; tcase++) { long k = sc.nextLong(); List<Integer> ans = new ArrayList<>(); long sum = 0; out: for (int i = 1; i < 14; i++) { for (int j = 10; j < 100; j++) { if (sum + dp[i][j] >= k) { k -= sum; ans.add(j); for (int ii = i - 1; ii >= 0; ii--) { int prev = ans.get(ans.size() - 1); for (int jj = 0; jj < 100; jj++) { if (isKado(prev, jj)) { if (k - dp[ii][jj] <= 0) { ans.add(jj); break; } else { k -= dp[ii][jj]; } } } } // pr.println(j); break out; } sum += dp[i][j]; } } StringBuilder s = new StringBuilder(); for (int i = 0; i < ans.size(); i++) { if (i == ans.size() - 1) { s.append(String.format("%02d", ans.get(i))); } else { s.append(ans.get(i) / 10); } } pr.println(s); } pr.close(); sc.close(); } private static boolean isKado(int a, int b) { int a1 = a / 10; int a2 = a % 10; int b1 = b / 10; int b2 = b % 10; if (a2 != b1 || a1 == a2 || b1 == b2 || a1 == b2) { return false; } if (a1 > a2 && a2 > b2) { return false; } if (a1 < a2 && a2 < b2) { return false; } return true; } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { // it = Arrays.asList(br.readLine().split(" ")).iterator(); it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }