結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー tentententen
提出日時 2021-07-29 20:57:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 2,129 bytes
コンパイル時間 2,295 ms
コンパイル使用メモリ 74,952 KB
実行使用メモリ 53,612 KB
最終ジャッジ日時 2023-10-12 19:01:50
合計ジャッジ時間 8,405 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,388 KB
testcase_01 AC 45 ms
49,396 KB
testcase_02 AC 47 ms
49,400 KB
testcase_03 AC 45 ms
49,408 KB
testcase_04 AC 46 ms
49,380 KB
testcase_05 AC 151 ms
53,612 KB
testcase_06 AC 143 ms
53,180 KB
testcase_07 AC 183 ms
53,552 KB
testcase_08 AC 114 ms
53,060 KB
testcase_09 AC 102 ms
52,980 KB
testcase_10 AC 48 ms
49,572 KB
testcase_11 AC 194 ms
53,548 KB
testcase_12 AC 46 ms
49,720 KB
testcase_13 AC 46 ms
49,340 KB
testcase_14 AC 57 ms
50,304 KB
testcase_15 AC 199 ms
53,296 KB
testcase_16 AC 211 ms
53,292 KB
testcase_17 AC 217 ms
53,124 KB
testcase_18 AC 207 ms
53,096 KB
testcase_19 AC 232 ms
53,068 KB
testcase_20 AC 221 ms
53,292 KB
testcase_21 AC 211 ms
52,940 KB
testcase_22 AC 240 ms
53,424 KB
testcase_23 AC 191 ms
51,176 KB
testcase_24 AC 219 ms
53,188 KB
testcase_25 AC 221 ms
53,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int kk = sc.nextInt();
        int ll = sc.nextInt();
        long[][][] dp = new long[20][n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 1; j <= ll; j++) {
                dp[0][i][(i + j) % n] = 1;
            }
        }
        for (int i = 1; i < 20; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    for (int l = 0; l < n; l++) {
                        dp[i][j][l] += dp[i - 1][j][k] * dp[i - 1][k][l] % MOD;
                        dp[i][j][l] %= MOD;
                    }
                }
            }
        }
        long[] current = new long[n];
        current[0] = 1;
        for (int i = 19; i >= 0 && kk > 0; i--) {
            if (kk >= (1 << i)) {
                kk -= (1 << i);
                long[] next = new long[n];
                for (int j = 0; j < n; j++) {
                    for (int k = 0; k < n; k++) {
                        next[k] += current[j] * dp[i][j][k] % MOD;
                        next[k] %= MOD;
                    }
                }
                current = next;
            }
            
        }
        StringBuilder sb = new StringBuilder();
        for (long x : current) {
            sb.append(x).append("\n");
        }
        System.out.print(sb);
    }
}

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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0