結果

問題 No.1112 冥界の音楽
ユーザー fastmathfastmath
提出日時 2020-07-10 21:59:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,104 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 164,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 17:06:11
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 6 ms
5,376 KB
testcase_20 AC 7 ms
5,376 KB
testcase_21 AC 7 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 23 ms
5,376 KB
testcase_25 AC 22 ms
5,376 KB
testcase_26 AC 20 ms
5,376 KB
testcase_27 AC 19 ms
5,376 KB
testcase_28 AC 21 ms
5,376 KB
testcase_29 AC 20 ms
5,376 KB
testcase_30 AC 19 ms
5,376 KB
testcase_31 AC 19 ms
5,376 KB
testcase_32 AC 21 ms
5,376 KB
testcase_33 AC 21 ms
5,376 KB
testcase_34 AC 19 ms
5,376 KB
testcase_35 AC 21 ms
5,376 KB
testcase_36 AC 23 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int MOD = 1000 * 1000 * 1000 + 7;

const int N =36;
void add(int &a, int b) {
    a += b;
    a %= MOD;
}   

void clear(int a[N][N], bool t) {
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            a[i][j] = t * (i == j);
}   
void cop(int a[N][N], int b[N][N]) {
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            a[i][j] = b[i][j];
}   
int t[N][N];
void add(int a[N][N], int b[N][N]) {
    clear(t, 0);
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            for (int k = 0; k < N; ++k)
                add(t[i][j], a[i][k] * b[k][j]);
    cop(a, t);
}   
void print(int a[N][N]) {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) 
            cout << a[i][j] << ' ';
        cout << '\n';
    }   
    cout << '\n';
}
int ans[N][N], cur[N][N];
void fp(int a[N][N], int p) {
    cop(cur, a);
    clear(ans, 1);
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) 
            add(ans, cur);
        add(cur, cur);
    }       
    cop(a, ans);
}   

int a[N][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int k, m, n;
    cin >> k >> m >> n;
                        
    for (int i = 0; i < m; ++i) {
        int aa, b, c;
        cin >> aa >> b >> c;

        --aa; --b; --c;

        int u = k * aa + b;
        int v = k * b + c;

        a[u][v] = 1;
    }   

    fp(a, n - 2);

    int ans = 0;
    for (int i = 0; i < k * k; ++i)
        for (int j = 0; j < k * k; ++j) {
            if (i<k && j%k==0) {
                add(ans, a[i][j]);
            }
        }
    cout << ans << endl;
}
0