結果
問題 | No.1340 おーじ君をさがせ |
ユーザー | miscalc |
提出日時 | 2022-02-17 00:54:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 4,731 bytes |
コンパイル時間 | 2,008 ms |
コンパイル使用メモリ | 211,604 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-29 07:23:42 |
合計ジャッジ時間 | 4,429 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 14 ms
6,940 KB |
testcase_12 | AC | 3 ms
6,940 KB |
testcase_13 | AC | 11 ms
6,940 KB |
testcase_14 | AC | 26 ms
6,944 KB |
testcase_15 | AC | 23 ms
6,940 KB |
testcase_16 | AC | 3 ms
6,940 KB |
testcase_17 | AC | 8 ms
6,940 KB |
testcase_18 | AC | 13 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 16 ms
6,944 KB |
testcase_22 | AC | 38 ms
6,944 KB |
testcase_23 | AC | 17 ms
6,944 KB |
testcase_24 | AC | 68 ms
6,940 KB |
testcase_25 | AC | 6 ms
6,944 KB |
testcase_26 | AC | 4 ms
6,944 KB |
testcase_27 | AC | 3 ms
6,940 KB |
testcase_28 | AC | 5 ms
6,940 KB |
testcase_29 | AC | 3 ms
6,940 KB |
testcase_30 | AC | 17 ms
6,940 KB |
testcase_31 | AC | 70 ms
6,940 KB |
testcase_32 | AC | 65 ms
6,940 KB |
testcase_33 | AC | 63 ms
6,940 KB |
testcase_34 | AC | 58 ms
6,940 KB |
testcase_35 | AC | 68 ms
6,940 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 5 ms
6,944 KB |
testcase_38 | AC | 68 ms
6,944 KB |
testcase_39 | AC | 21 ms
6,940 KB |
testcase_40 | AC | 21 ms
6,944 KB |
testcase_41 | AC | 22 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 1 ms
6,944 KB |
testcase_45 | AC | 1 ms
6,940 KB |
testcase_46 | AC | 14 ms
6,940 KB |
testcase_47 | AC | 15 ms
6,944 KB |
testcase_48 | AC | 17 ms
6,940 KB |
testcase_49 | AC | 16 ms
6,944 KB |
testcase_50 | AC | 16 ms
6,940 KB |
testcase_51 | AC | 16 ms
6,944 KB |
testcase_52 | AC | 29 ms
6,940 KB |
testcase_53 | AC | 29 ms
6,940 KB |
testcase_54 | AC | 30 ms
6,940 KB |
testcase_55 | AC | 24 ms
6,940 KB |
testcase_56 | AC | 2 ms
6,940 KB |
testcase_57 | AC | 2 ms
6,940 KB |
testcase_58 | AC | 2 ms
6,944 KB |
testcase_59 | AC | 11 ms
6,944 KB |
testcase_60 | AC | 2 ms
6,940 KB |
testcase_61 | AC | 11 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tlll = tuple<ll, ll, ll>; constexpr ll INF = 1LL << 60; template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll safemod(ll A, ll M) {return (A % M + M) % M;} ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;} ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);} template<class T> void unique(vector<T> &V) {V.erase(unique(V.begin(), V.end()), V.end());} template<class T> void sortunique(vector<T> &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) template<class T, T(*e0)(), T(*e1)()> struct matrix : vector<vector<T>> { using vector<vector<T>>::vector; using vector<vector<T>>::operator=; matrix(int n, int m, T a = e0()) { (*this) = vector<vector<T>>(n, vector<T>(m, 0)); for (int i = 0; i < min(n, m); i++) { (*this)[i][i] = a; } } matrix operator-() const { int N = (*this).size(), M = (*this)[0].size(); matrix res(*this); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { res[i][j] = -res[i][j]; } } return res; } matrix &operator+=(const matrix &A) { int N = (*this).size(), M = (*this)[0].size(); assert(A.size() == N && A[0].size() == M); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { (*this)[i][j] += A[i][j]; } } return *this; } matrix &operator-=(const matrix &A) { return (*this) += -A; } matrix &operator*=(const T x) { int N = (*this).size(), M = (*this)[0].size(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { (*this)[i][j] *= x; } } return *this; } matrix &operator/=(const T x) { int N = (*this).size(), M = (*this)[0].size(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { (*this)[i][j] /= x; } } return *this; } friend matrix &operator*=(const T x, matrix &A) { return A *= x; } vector<T> operator*(const vector<T> &v) { int N = (*this).size(), M = (*this)[0].size(); assert(v.size() == M); vector<T> res(N, e0()); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { res[i] += (*this)[i][j] * v[j]; } } return res; } matrix operator*(const matrix &A) { int N = (*this).size(), M = (*this)[0].size(); assert(A.size() == M); int K = A[0].size(); matrix res(N, K, e0()); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { for (int k = 0; k < K; k++) { res[i][k] += (*this)[i][j] * A[j][k]; } } } return res; } matrix pow(ll k) { int N = (*this).size(), M = (*this)[0].size(); assert(N == M); matrix res(N, N, e1()), tmp(*this); while (k > 0) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } matrix operator+(const matrix &A) const { return matrix(*this) += A; } matrix operator-(const matrix &A) const { return matrix(*this) -= A; } matrix operator*(const T x) const { return matrix(*this) *= x; } matrix operator/(const T x) const { return matrix(*this) /= x; } friend matrix operator*(const T x, matrix &A) { return A *= x; } matrix &operator*=(const matrix &A) { return (*this) = (*this) * A; } }; // e0, e1 は加法, 乗法の単位元。問題によって書き換える template <class T> constexpr T e0() { return 0; } template <class T> constexpr T e1() { return 1; } struct myll { ll x; myll(ll v = 0) : x(v) {} // 加法, 乗法を問題によって書き換える myll &operator+=(myll y) { x |= y.x; return *this; } myll &operator*=(myll y) { x &= y.x; return *this; } myll operator+(myll y) const { return myll(*this) += y; } myll operator*(myll y) const { return myll(*this) *= y; } }; int main() { ll N, M, T; cin >> N >> M >> T; matrix<myll, e0, e1> mat(N, N); for (ll i = 0; i < M; i++) { ll a, b; cin >> a >> b; mat.at(b).at(a) = 1; } vector<myll> A(N, 0); A.at(0) = 1; auto B = mat.pow(T) * A; ll ans = 0; for (ll i = 0; i < N; i++) { if (B.at(i).x == 1) ans++; } cout << ans << endl; }