結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-13 23:40:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,577 bytes
コンパイル時間 2,693 ms
コンパイル使用メモリ 112,368 KB
実行使用メモリ 5,180 KB
最終ジャッジ日時 2023-09-04 11:55:45
合計ジャッジ時間 5,237 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
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 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

const ll modc = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x=0) : x((x%modc+modc)%modc) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += modc-a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= modc;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(modc-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    bool operator == (const mint& a) const{
        return x == a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    friend istream& operator>>(istream& ip, mint&m) {
        ip >> m.x;
        return ip;
    }
};

vector<vector<mint>> dot(vector<vector<mint>> &a, vector<vector<mint>> &b){
    int M = a.size();
    vector<vector<mint>> c(M, vector<mint>(M));
    for (int i=0; i<M; i++){
        for (int k=0; k<M; k++){
            for (int j=0; j<M; j++) c[i][j] += (a[i][k] * b[k][j]);
        }
    }
    return c;
}

//A^N
vector<vector<mint>> pow(vector<vector<mint>> A, ll N){
    int M = A.size();
    vector<vector<mint>> B(M, vector<mint>(M));
    for (int i=0; i<M; i++) B[i][i] = 1;
    while(N){
        if (N % 2 == 1) B = dot(B, A);
        N >>= 1;
        A = dot(A, A);
    }
    return B;
}

int main(){

    ll N, K, L;
    cin >> N >> K >> L;
    vector<vector<mint>> mat(N, vector<mint>(N));

    for (int i=0; i<N; i++){
        for (int j=1; j<=L; j++) mat[(i+j)%N][j] = 1;
    }

    mat = pow(mat, K);
    for (int i=0; i<N; i++) cout << mat[i][0] << endl;
    
    return 0;
}
0