結果

問題 No.220 世界のなんとか2
ユーザー htensaihtensai
提出日時 2020-01-14 17:30:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 1,000 ms
コード長 878 bytes
コンパイル時間 3,857 ms
コンパイル使用メモリ 78,704 KB
実行使用メモリ 56,208 KB
最終ジャッジ日時 2023-08-26 21:11:48
合計ジャッジ時間 5,884 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
56,100 KB
testcase_01 AC 107 ms
56,172 KB
testcase_02 AC 111 ms
56,176 KB
testcase_03 AC 107 ms
56,108 KB
testcase_04 AC 111 ms
55,856 KB
testcase_05 AC 111 ms
55,708 KB
testcase_06 AC 111 ms
55,740 KB
testcase_07 AC 112 ms
55,936 KB
testcase_08 AC 112 ms
55,852 KB
testcase_09 AC 114 ms
55,968 KB
testcase_10 AC 116 ms
55,832 KB
testcase_11 AC 113 ms
55,800 KB
testcase_12 AC 116 ms
56,144 KB
testcase_13 AC 111 ms
55,884 KB
testcase_14 AC 109 ms
55,588 KB
testcase_15 AC 110 ms
54,104 KB
testcase_16 AC 105 ms
56,004 KB
testcase_17 AC 109 ms
56,208 KB
testcase_18 AC 111 ms
56,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] dp = new long[3][n + 1];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 10; j++) {
                if (j == 3) {
                    continue;
                }
                dp[j % 3][i] += dp[0][i - 1];
                dp[(j + 1) % 3][i] += dp[1][i - 1];
                dp[(j + 2) % 3][i] += dp[2][i - 1];
            }
        }
        if (n < 19) {
            long ans = (long)(Math.pow(10, n)) - dp[1][n] - dp[2][n] - 1;
            System.out.println(ans);
        } else {
            long base = (long)(Math.pow(10, n) / 2);
            long ans = base - dp[1][n] + base - dp[2][n] - 1;
            System.out.println(ans);
        }
    }
}
0