結果
問題 | No.1521 Playing Musical Chairs Alone |
ユーザー | tenten |
提出日時 | 2024-01-11 10:36:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 220 ms / 2,000 ms |
コード長 | 2,747 bytes |
コンパイル時間 | 3,141 ms |
コンパイル使用メモリ | 85,048 KB |
実行使用メモリ | 53,904 KB |
最終ジャッジ日時 | 2024-09-27 20:27:02 |
合計ジャッジ時間 | 7,959 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
50,420 KB |
testcase_01 | AC | 59 ms
50,852 KB |
testcase_02 | AC | 62 ms
51,328 KB |
testcase_03 | AC | 59 ms
50,900 KB |
testcase_04 | AC | 59 ms
51,004 KB |
testcase_05 | AC | 179 ms
53,764 KB |
testcase_06 | AC | 150 ms
53,764 KB |
testcase_07 | AC | 161 ms
53,596 KB |
testcase_08 | AC | 114 ms
53,904 KB |
testcase_09 | AC | 125 ms
53,644 KB |
testcase_10 | AC | 67 ms
51,252 KB |
testcase_11 | AC | 197 ms
53,604 KB |
testcase_12 | AC | 62 ms
51,184 KB |
testcase_13 | AC | 62 ms
50,732 KB |
testcase_14 | AC | 72 ms
51,256 KB |
testcase_15 | AC | 194 ms
53,728 KB |
testcase_16 | AC | 211 ms
53,848 KB |
testcase_17 | AC | 220 ms
53,532 KB |
testcase_18 | AC | 200 ms
53,688 KB |
testcase_19 | AC | 209 ms
53,652 KB |
testcase_20 | AC | 211 ms
53,768 KB |
testcase_21 | AC | 212 ms
53,744 KB |
testcase_22 | AC | 216 ms
53,768 KB |
testcase_23 | AC | 186 ms
53,676 KB |
testcase_24 | AC | 213 ms
53,676 KB |
testcase_25 | AC | 211 ms
53,832 KB |
ソースコード
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 count = sc.nextInt(); int move = sc.nextInt(); long[][][] matrix = new long[20][n][n]; for (int i = 0; i < n; i++) { for (int j = 1; j <= move; j++) { matrix[0][i][(i - j + n) % 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 = 20; i >= 0; i--) { if (count < (1 << i)) { continue; } count -= (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(); } }