結果

問題 No.220 世界のなんとか2
ユーザー tentententen
提出日時 2022-08-19 19:35:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 53 ms / 1,000 ms
コード長 1,570 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 77,552 KB
実行使用メモリ 50,324 KB
最終ジャッジ日時 2024-04-16 22:36:43
合計ジャッジ時間 3,696 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
50,260 KB
testcase_01 AC 50 ms
50,292 KB
testcase_02 AC 50 ms
49,948 KB
testcase_03 AC 50 ms
50,324 KB
testcase_04 AC 50 ms
50,220 KB
testcase_05 AC 50 ms
49,880 KB
testcase_06 AC 51 ms
50,312 KB
testcase_07 AC 52 ms
50,144 KB
testcase_08 AC 50 ms
50,280 KB
testcase_09 AC 50 ms
50,236 KB
testcase_10 AC 51 ms
50,196 KB
testcase_11 AC 52 ms
50,292 KB
testcase_12 AC 52 ms
49,740 KB
testcase_13 AC 52 ms
50,036 KB
testcase_14 AC 51 ms
50,156 KB
testcase_15 AC 52 ms
50,172 KB
testcase_16 AC 50 ms
50,180 KB
testcase_17 AC 50 ms
50,264 KB
testcase_18 AC 53 ms
50,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        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 < 3; j++) {
                for (int k = 0; k < 10; k++) {
                    if (k == 3) {
                        continue;
                    }
                    dp[i][(j * 10 + k) % 3] += dp[i - 1][j];
                }
            }
        }
        long ans = pow(10, n);
        for (int i = 1; i < 3; i++) {
            ans -= dp[n][i];
        }
        System.out.println(ans - 1);
    }
    
    static long pow(int x, int p) {
        if (p == 0) {
            return 1;
        } else {
            return x * pow(x, p - 1);
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0