結果
問題 | No.362 門松ナンバー |
ユーザー |
|
提出日時 | 2016-08-04 23:24:45 |
言語 | Java (openjdk 23) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
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);}}}