結果

問題 No.220 世界のなんとか2
ユーザー uafr_csuafr_cs
提出日時 2015-10-12 19:29:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 1,000 ms
コード長 1,689 bytes
コンパイル時間 3,782 ms
コンパイル使用メモリ 80,748 KB
実行使用メモリ 57,788 KB
最終ジャッジ日時 2023-09-28 12:41:28
合計ジャッジ時間 7,485 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,812 KB
testcase_01 AC 127 ms
55,608 KB
testcase_02 AC 124 ms
55,800 KB
testcase_03 AC 128 ms
55,876 KB
testcase_04 AC 128 ms
55,744 KB
testcase_05 AC 129 ms
55,684 KB
testcase_06 AC 129 ms
57,788 KB
testcase_07 AC 127 ms
55,800 KB
testcase_08 AC 126 ms
53,840 KB
testcase_09 AC 126 ms
55,640 KB
testcase_10 AC 126 ms
55,792 KB
testcase_11 AC 127 ms
55,992 KB
testcase_12 AC 127 ms
55,872 KB
testcase_13 AC 130 ms
56,032 KB
testcase_14 AC 128 ms
55,852 KB
testcase_15 AC 127 ms
55,972 KB
testcase_16 AC 126 ms
56,012 KB
testcase_17 AC 128 ms
56,000 KB
testcase_18 AC 128 ms
53,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;
import java.util.function.LongPredicate;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int P = sc.nextInt();
		
		final int MOD = 3;
		final BigInteger big_MOD = BigInteger.valueOf(MOD);
		
		long[] pow10 = new long[P + 1];
		for(int i = 0; i <= P; i++){
			pow10[i] = (i == 0 ? 1 : pow10[i - 1] * 10);
		}
			
		BigInteger[][] DP = new BigInteger[P + 1][MOD];
		for(int i = 0; i <= P; i++){
			for(int j = 0; j < MOD; j++){
				DP[i][j] = BigInteger.ZERO;
			}
		}
		
		for(int digit = 1; digit <= P; digit++){
			for(int first = 0; first <= 9; first++){
				if(first == 3){
					for(int i = 0; i < MOD; i++){
						DP[digit][i] = DP[digit][i].add(BigInteger.TEN.pow(digit - 1).divide(big_MOD).add(i == 0 ? BigInteger.ONE : BigInteger.ZERO));
						//DP[digit][i] += (pow10[digit - 1] / MOD) + (i == 0 ? 1 : 0);
					}
				}else{
					for(int i = 0; i < MOD; i++){
						DP[digit][(first + i) % MOD] = DP[digit][(first + i) % MOD].add(DP[digit - 1][i]);
						//DP[digit][(first + i) % MOD] += DP[digit - 1][i];
					}
				}
			}
		}
		System.out.println(DP[P][1].add(DP[P][2]).add(BigInteger.TEN.pow(P).divide(big_MOD)));
		/*
		System.out.println(LongStream.range(1, pow10[P]).filter(new LongPredicate() {
			public boolean test(long value) {
				return value % 3 == 0 || Long.toString(value).contains("3");
			}
		}).count());
		/*
		System.out.println(Arrays.deepToString(DP));
		*/
	}

}
0