結果
問題 | No.1340 おーじ君をさがせ |
ユーザー | Manuel1024 |
提出日時 | 2021-03-21 13:37:01 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,366 bytes |
コンパイル時間 | 785 ms |
コンパイル使用メモリ | 74,996 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-11-22 05:48:08 |
合計ジャッジ時間 | 54,528 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | AC | 2 ms
8,576 KB |
testcase_02 | AC | 2 ms
8,704 KB |
testcase_03 | AC | 2 ms
8,832 KB |
testcase_04 | AC | 2 ms
10,496 KB |
testcase_05 | AC | 2 ms
8,576 KB |
testcase_06 | AC | 2 ms
10,496 KB |
testcase_07 | AC | 2 ms
8,576 KB |
testcase_08 | AC | 2 ms
10,496 KB |
testcase_09 | AC | 2 ms
8,576 KB |
testcase_10 | WA | - |
testcase_11 | AC | 909 ms
8,576 KB |
testcase_12 | AC | 126 ms
10,496 KB |
testcase_13 | AC | 677 ms
5,248 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 1,634 ms
5,248 KB |
testcase_16 | AC | 95 ms
5,248 KB |
testcase_17 | AC | 474 ms
5,248 KB |
testcase_18 | AC | 956 ms
5,248 KB |
testcase_19 | AC | 37 ms
5,248 KB |
testcase_20 | AC | 8 ms
5,248 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | TLE | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | AC | 2 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | TLE | - |
testcase_39 | AC | 1,266 ms
5,248 KB |
testcase_40 | AC | 1,305 ms
5,248 KB |
testcase_41 | AC | 1,320 ms
5,248 KB |
testcase_42 | AC | 2 ms
5,248 KB |
testcase_43 | AC | 2 ms
5,248 KB |
testcase_44 | AC | 3 ms
5,248 KB |
testcase_45 | AC | 2 ms
5,248 KB |
testcase_46 | AC | 941 ms
5,248 KB |
testcase_47 | AC | 1,028 ms
5,248 KB |
testcase_48 | AC | 1,141 ms
5,248 KB |
testcase_49 | AC | 1,136 ms
5,248 KB |
testcase_50 | AC | 1,139 ms
5,248 KB |
testcase_51 | AC | 1,158 ms
5,248 KB |
testcase_52 | TLE | - |
testcase_53 | TLE | - |
testcase_54 | TLE | - |
testcase_55 | AC | 1,714 ms
5,248 KB |
testcase_56 | WA | - |
testcase_57 | AC | 2 ms
5,248 KB |
testcase_58 | AC | 2 ms
5,248 KB |
testcase_59 | AC | 654 ms
5,248 KB |
testcase_60 | AC | 2 ms
5,248 KB |
testcase_61 | AC | 661 ms
5,248 KB |
ソースコード
#include <iostream> #include <vector> using namespace std; using ll = long long int; template<typename T> class Matrix{ private: vector<vector<T>> mat; int row; int column; public: Matrix(int r = 1, int c = 1){ this->row = r; this->column = c; this->mat = vector<vector<T>>(this->row, vector<T>(this->column, 0)); } Matrix(vector<vector<T>> initmat){ this->mat = initmat; this->row = this->mat.size(); this->column = this->mat[0].size(); } vector<T> &operator[](const int rowind){ return mat[rowind]; } vector<T> operator[](const int rowind) const { return mat[rowind]; } const int getrow() const { return this->row; } const int getcol() const { return this->column; } Matrix operator+(const Matrix &other) const { if(this->row != other.getrow() || this->column != other.getcol()){ cerr << "Matrix calc error(add)" << endl; abort(); } Matrix ans(this->row, this->column); for(int i = 0; i < this->row; i++){ for(int j = 0; j < this->column; j++) ans[i][j] = this->mat[i][j] + other[i][j]; } return ans; } Matrix operator-(const Matrix &other) const { if(this->row != other.getrow() || this->column != other.getcol()){ cerr << "Matrix calc error(sub)" << endl; abort(); } Matrix ans(this->row, this->column); for(int i = 0; i < this->row; i++){ for(int j = 0; j < this->column; j++) ans[i][j] = this->mat[i][j] - other[i][j]; } return ans; } Matrix operator*(const Matrix &other) const { if(this->column != other.getrow()){ cerr << "Matrix calc error(mult)" << endl; abort(); } Matrix ans(this->row, other.getcol()); for(int i = 0; i < this->row; i++){ for(int j = 0; j < other.getcol(); j++){ for(int k = 0; k < this->column; k++) ans[i][j] += this->mat[i][k] * other[k][j]; } } return ans; } }; template<typename T> Matrix<T> modpow(Matrix<T> a, ll x, ll mod){ if(a.getrow() != a.getcol()){ cerr << "Matrix calc error(pow)" << endl; abort(); } Matrix<T> ans(a.getrow(), a.getcol()); for(int i = 0; i < ans.getrow(); i++) ans[i][i] = 1; auto modmult = [](const Matrix<T> &a, const Matrix<T> &b, const ll mod){ Matrix<T> res(a.getrow(), b.getcol()); for(int i = 0; i < a.getrow(); i++){ for(int j = 0; j < b.getcol(); j++){ for(int k = 0; k < a.getcol(); k++){ res[i][j] += a[i][k] * b[k][j]; } if(res[i][j] > 0) res[i][j] = 1; } } return res; }; while(x > 0){ if(x & 1){ ans = modmult(ans, a, mod); } a = modmult(a, a, mod); x >>= 1; } return ans; } int main(){ int n, m, t; cin >> n >> m >> t; Matrix<int> mat(n, n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; mat[a][b] = 1; } mat = modpow(mat, t, 1000000007); int ans = 0; for(int i = 0; i < n; i++){ ans += mat[0][i]; } cout << ans << endl; return 0; }