結果

問題 No.220 世界のなんとか2
ユーザー GrenacheGrenache
提出日時 2015-06-01 00:52:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 1,000 ms
コード長 672 bytes
コンパイル時間 4,170 ms
コンパイル使用メモリ 72,184 KB
実行使用メモリ 56,096 KB
最終ジャッジ日時 2023-09-20 18:10:17
合計ジャッジ時間 6,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,752 KB
testcase_01 AC 124 ms
55,988 KB
testcase_02 AC 124 ms
55,992 KB
testcase_03 AC 125 ms
56,072 KB
testcase_04 AC 123 ms
55,796 KB
testcase_05 AC 124 ms
55,916 KB
testcase_06 AC 125 ms
55,888 KB
testcase_07 AC 125 ms
55,704 KB
testcase_08 AC 124 ms
55,588 KB
testcase_09 AC 126 ms
56,096 KB
testcase_10 AC 124 ms
55,708 KB
testcase_11 AC 123 ms
55,752 KB
testcase_12 AC 124 ms
55,924 KB
testcase_13 AC 123 ms
55,732 KB
testcase_14 AC 123 ms
55,560 KB
testcase_15 AC 123 ms
55,632 KB
testcase_16 AC 122 ms
55,736 KB
testcase_17 AC 126 ms
55,876 KB
testcase_18 AC 125 ms
56,036 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