結果

問題 No.220 世界のなんとか2
ユーザー rf141rf141
提出日時 2015-06-19 05:42:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 1,000 ms
コード長 965 bytes
コンパイル時間 3,789 ms
コンパイル使用メモリ 72,004 KB
実行使用メモリ 56,144 KB
最終ジャッジ日時 2023-09-21 09:44:03
合計ジャッジ時間 7,728 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,004 KB
testcase_01 AC 126 ms
55,992 KB
testcase_02 AC 129 ms
55,520 KB
testcase_03 AC 128 ms
55,836 KB
testcase_04 AC 129 ms
53,520 KB
testcase_05 AC 128 ms
55,632 KB
testcase_06 AC 130 ms
55,852 KB
testcase_07 AC 129 ms
55,468 KB
testcase_08 AC 128 ms
55,724 KB
testcase_09 AC 129 ms
55,896 KB
testcase_10 AC 128 ms
55,728 KB
testcase_11 AC 131 ms
55,584 KB
testcase_12 AC 128 ms
55,836 KB
testcase_13 AC 128 ms
55,828 KB
testcase_14 AC 128 ms
55,984 KB
testcase_15 AC 127 ms
55,624 KB
testcase_16 AC 127 ms
55,884 KB
testcase_17 AC 128 ms
56,144 KB
testcase_18 AC 127 ms
55,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder220 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int p = sc.nextInt();

        long[] dp = new long[p + 1];
        long[][] dp2 = new long[3][p + 1];

        long base = 1;
        for (int i = 1; i <= p; i++) {
            for (int j = 0; j < 10; j++) {
                if (j == 3) {
                    dp[i] += base;
                } else {
                    dp[i] += dp[i - 1];

                    if (base == 1) {
                        dp2[j % 3][i]++;
                    } else {
                        for (int k = 0; k < 3; k++) {
                            dp2[(int)((base * j + k) % 3)][i] += dp2[k][i - 1];
                        }
                    }
                }
            }
            
            base *= 10;
        }
        
        System.out.println(dp[p] + dp2[0][p] - 1);
        
        sc.close();
    }
}
0