結果

問題 No.220 世界のなんとか2
ユーザー tentententen
提出日時 2020-10-26 10:08:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 1,000 ms
コード長 908 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 71,036 KB
実行使用メモリ 57,640 KB
最終ジャッジ日時 2023-09-29 02:30:48
合計ジャッジ時間 5,844 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,692 KB
testcase_01 AC 130 ms
55,644 KB
testcase_02 AC 128 ms
55,956 KB
testcase_03 AC 129 ms
57,640 KB
testcase_04 AC 128 ms
55,904 KB
testcase_05 AC 130 ms
55,884 KB
testcase_06 AC 129 ms
55,956 KB
testcase_07 AC 129 ms
55,732 KB
testcase_08 AC 128 ms
55,784 KB
testcase_09 AC 128 ms
55,708 KB
testcase_10 AC 128 ms
55,708 KB
testcase_11 AC 128 ms
55,744 KB
testcase_12 AC 129 ms
55,948 KB
testcase_13 AC 127 ms
55,680 KB
testcase_14 AC 129 ms
55,928 KB
testcase_15 AC 128 ms
55,664 KB
testcase_16 AC 130 ms
55,760 KB
testcase_17 AC 130 ms
57,508 KB
testcase_18 AC 128 ms
55,796 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[n + 1][3];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 10; j++) {
                if (j == 3) {
                    continue;
                }
                for (int k = 0; k < 3; k++) {
                    dp[i][(k * 10 + j) % 3] += dp[i - 1][k];
                }
            }
        }
        long sum = 0;
        for (long x : dp[n]) {
            sum += x;
        }
        long total = pow(10, n) - sum;
        long ans = total + dp[n][0] - 1;
        System.out.println(ans);
    }
    
    static long pow(long x, long times) {
        long ret = 1;
        for (int i = 0; i < times; i++) {
            ret *= x;
        }
        return ret;
    }
}
0