結果

問題 No.1340 おーじ君をさがせ
ユーザー sapphire__15sapphire__15
提出日時 2021-01-15 23:31:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 2,203 bytes
コンパイル時間 1,216 ms
コンパイル使用メモリ 121,004 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 16:46:55
合計ジャッジ時間 6,052 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,360 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 47 ms
4,376 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 36 ms
4,380 KB
testcase_14 AC 97 ms
4,380 KB
testcase_15 AC 84 ms
4,376 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 48 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 34 ms
4,376 KB
testcase_22 AC 82 ms
4,384 KB
testcase_23 AC 35 ms
4,376 KB
testcase_24 AC 155 ms
4,380 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 37 ms
4,380 KB
testcase_31 AC 153 ms
4,376 KB
testcase_32 AC 228 ms
4,376 KB
testcase_33 AC 231 ms
4,380 KB
testcase_34 AC 210 ms
4,376 KB
testcase_35 AC 240 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 245 ms
4,380 KB
testcase_39 AC 63 ms
4,376 KB
testcase_40 AC 65 ms
4,376 KB
testcase_41 AC 70 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 48 ms
4,380 KB
testcase_47 AC 47 ms
4,376 KB
testcase_48 AC 53 ms
4,376 KB
testcase_49 AC 56 ms
4,380 KB
testcase_50 AC 57 ms
4,380 KB
testcase_51 AC 56 ms
4,380 KB
testcase_52 AC 103 ms
4,376 KB
testcase_53 AC 107 ms
4,376 KB
testcase_54 AC 114 ms
4,376 KB
testcase_55 AC 78 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 32 ms
4,376 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 33 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>

typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &_l, const T b) {
    if (_l < b) {
        _l = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
    if (_l > b) {
        _l = b;
        return true;
    }
    return false;
}

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

vector<vector<bool>> product(const vector<vector<bool>> &a, const vector<vector<bool>> &b) {
    int n = a.size();
    vector<vector<bool>> ret(n, vector<bool>(n));
    rip(i,n,0) rip(j,n,0) {
        rip(k,n,0) ret[i][j] = ret[i][j] | (a[i][k]&b[k][j]);
    }
    return ret;
}

int main() {
    int n, m; cin >> n >> m;
    ll t; cin >> t;
    vector<vector<bool>> da(n, vector<bool>(n));
    rip(i,m,0) {
        int a, b; cin >> a >> b;
        da[a][b] = true;
    }
    vector<vector<bool>> aft(n, vector<bool>(n));
    rip(i,n,0) aft[i][i] = true;
    while(t) {
        if(t&1) aft = product(aft, da);
        da = product(da, da);
        t >>= 1;
    }
    int ans = 0;
    rip(i,n,0) ans += aft[0][i];
    cout << ans << endl;
}
0