結果

問題 No.1340 おーじ君をさがせ
ユーザー merom686merom686
提出日時 2021-01-15 23:33:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,523 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 86,012 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 16:47:37
合計ジャッジ時間 4,043 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 32 ms
4,376 KB
testcase_11 AC 20 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 17 ms
4,380 KB
testcase_17 AC 18 ms
4,376 KB
testcase_18 AC 15 ms
4,376 KB
testcase_19 AC 19 ms
4,376 KB
testcase_20 AC 17 ms
4,376 KB
testcase_21 AC 33 ms
4,380 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 35 ms
4,380 KB
testcase_24 AC 33 ms
4,380 KB
testcase_25 AC 37 ms
4,380 KB
testcase_26 AC 34 ms
4,380 KB
testcase_27 AC 36 ms
4,380 KB
testcase_28 AC 32 ms
4,380 KB
testcase_29 AC 34 ms
4,380 KB
testcase_30 AC 35 ms
4,376 KB
testcase_31 AC 34 ms
4,376 KB
testcase_32 AC 34 ms
4,376 KB
testcase_33 AC 34 ms
4,380 KB
testcase_34 AC 30 ms
4,376 KB
testcase_35 AC 36 ms
4,376 KB
testcase_36 AC 33 ms
4,376 KB
testcase_37 AC 35 ms
4,376 KB
testcase_38 AC 34 ms
4,380 KB
testcase_39 AC 11 ms
4,376 KB
testcase_40 AC 11 ms
4,380 KB
testcase_41 AC 11 ms
4,376 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 17 ms
4,380 KB
testcase_45 AC 8 ms
4,376 KB
testcase_46 AC 8 ms
4,376 KB
testcase_47 AC 9 ms
4,376 KB
testcase_48 AC 9 ms
4,376 KB
testcase_49 AC 8 ms
4,376 KB
testcase_50 AC 8 ms
4,376 KB
testcase_51 AC 8 ms
4,376 KB
testcase_52 AC 16 ms
4,376 KB
testcase_53 AC 15 ms
4,376 KB
testcase_54 AC 15 ms
4,376 KB
testcase_55 AC 13 ms
4,376 KB
testcase_56 AC 17 ms
4,376 KB
testcase_57 AC 18 ms
4,376 KB
testcase_58 AC 19 ms
4,376 KB
testcase_59 AC 6 ms
4,376 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

template <class T, int N>
struct ColumnVector {
    struct SquareMatrix {
        static SquareMatrix E() {
            SquareMatrix r;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    r.a[i][j] = i == j;
                }
            }
            return r;
        }
        ColumnVector operator*(const ColumnVector &v) const {
            ColumnVector r;
            for (int i = 0; i < N; i++) {
                T t = 0;
                for (int k = 0; k < N; k++) {
                    t += a[i][k] * v.a[k];
                }
                r.a[i] = t != 0;
            }
            return r;
        }
        SquareMatrix operator*(const SquareMatrix &x) const {
            SquareMatrix r;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    T t = 0;
                    for (int k = 0; k < N; k++) {
                        t += a[i][k] * x.a[k][j];
                    }
                    r.a[i][j] = t != 0;
                }
            }
            return r;
        }
        SquareMatrix pow(ll k) const {
            SquareMatrix r = E(), t = *this;
            for (; k != 0; k /= 2) {
                if (k & 1) r = r * t;
                t = t * t;
            }
            return r;
        }
        void print() const {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    cout << a[i][j].i << " \n"[j == N - 1];
                }
            }
        }
        T a[N][N];
    };
    void print() const {
        for (int i = 0; i < N; i++) {
            cout << a[i].i << " \n"[i == N - 1];
        }
    }
    T a[N];
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    ll t;
    cin >> t;

    ColumnVector<int, 100> v;
    for (int i = 0; i < n; i++) {
        v.a[i] = i == 0;
    }

    ColumnVector<int, 100>::SquareMatrix x;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            x.a[i][j] = 0;
        }
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;

        x.a[b][a] = 1;
    }

    v = x.pow(t) * v;

    int r = 0;
    for (int i = 0; i < n; i++) {
        r += v.a[i];
    }

    cout << r << endl;

    return 0;
}
0