結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー tentententen
提出日時 2023-07-18 16:29:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,725 bytes
コンパイル時間 4,505 ms
コンパイル使用メモリ 84,832 KB
実行使用メモリ 57,244 KB
最終ジャッジ日時 2023-10-18 19:48:14
合計ジャッジ時間 10,998 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
53,940 KB
testcase_01 AC 67 ms
54,092 KB
testcase_02 AC 68 ms
54,092 KB
testcase_03 AC 67 ms
54,524 KB
testcase_04 AC 67 ms
53,936 KB
testcase_05 WA -
testcase_06 AC 169 ms
57,108 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 66 ms
54,084 KB
testcase_13 AC 68 ms
54,500 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 236 ms
57,080 KB
testcase_23 WA -
testcase_24 AC 237 ms
57,140 KB
testcase_25 AC 240 ms
57,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 k = sc.nextInt();
        int l = sc.nextInt();
        long[][][] matrix = new long[20][n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 1; j <= l; j++) {
                matrix[0][i][(i + j) % n] = 1;
            }
        }
        for (int i = 1; i < 20; i++) {
            for (int a = 0; a < n; a++) {
                for (int b = 0; b < n; b++) {
                    for (int c = 0; c < n; c++) {
                        matrix[i][a][c] += matrix[i - 1][a][b] * matrix[i - 1][b][c] % MOD;
                        matrix[i][a][c] %= MOD;
                    }
                }
            }
        }
        long[] ans = new long[n];
        ans[0] = 1;
        for (int i = 19; i >= 0; i--) {
            if (k < (1 << i)) {
                continue;
            }
            k -= (1 << i);
            long[] next = new long[n];
            for (int a = 0; a < n; a++) {
                for (int b = 0; b < n; b++) {
                    next[a] += matrix[i][a][b] * ans[b] % MOD;
                    next[a] %= MOD;
                }
            }
            ans = next;
        }
        System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new)));
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0