結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー tnakao0123tnakao0123
提出日時 2021-05-30 17:59:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,960 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 92,104 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-08 15:11:49
合計ジャッジ時間 5,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 52 ms
4,380 KB
testcase_06 AC 39 ms
4,380 KB
testcase_07 AC 66 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 5 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 117 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 129 ms
4,376 KB
testcase_16 AC 150 ms
4,376 KB
testcase_17 AC 147 ms
4,380 KB
testcase_18 AC 134 ms
4,380 KB
testcase_19 AC 133 ms
4,380 KB
testcase_20 AC 151 ms
4,380 KB
testcase_21 AC 148 ms
4,380 KB
testcase_22 AC 136 ms
4,380 KB
testcase_23 AC 118 ms
4,376 KB
testcase_24 AC 136 ms
4,380 KB
testcase_25 AC 191 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1521.cc:  No.1521 Playing Musical Chairs Alone - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;
typedef int vec[MAX_N];
typedef vec mat[MAX_N];

/* global variables */

mat ma, mb, mc;

/* subroutines */

inline void initvec(const int n, vec a) { memset(a, 0, sizeof(vec)); }
inline void initmat(const int n, mat a) { memset(a, 0, sizeof(mat)); }

inline void unitmat(const int n, mat a) {
  initmat(n, a);
  for (int i = 0; i < n; i++) a[i][i] = 1;
}

inline void copymat(const int n, const mat a, mat b) {
  memcpy(b, a, sizeof(mat));
}

inline void mulmat(const int n, const mat a, const mat b, mat c) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      c[i][j] = 0;
      for (int k = 0; k < n; k++)
        c[i][j] = (c[i][j] + (ll)a[i][k] * b[k][j] % MOD) % MOD;
    }
}

inline void powmat(const int n, const mat a, int b, mat c) {
  mat s, t;
  copymat(n, a, s);
  unitmat(n, c);

  while (b > 0) {
    if (b & 1) {
      mulmat(n, c, s, t);
      copymat(n, t, c);
    }

    mulmat(n, s, s, t);
    copymat(n, t, s);
    b >>= 1;
  }
}

void printmat(const int n, const mat a) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j) putchar(' ');
      printf("%d", a[i][j]);
    }
    putchar('\n');
  }
}

/* main */

int main() {
  int n, k, l;
  scanf("%d%d%d", &n, &k, &l);

  for (int i = 0; i < n; i++)
    for (int j = 1; j <= l; j++)
      ma[(i + j) % n][i] = 1;

  powmat(n, ma, k, mb);

  for (int i = 0; i < n; i++) printf("%d\n", mb[i][0]);
  return 0;
}
0