結果
問題 | No.1660 Matrix Exponentiation |
ユーザー | stoq |
提出日時 | 2021-08-03 16:50:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,621 bytes |
コンパイル時間 | 2,357 ms |
コンパイル使用メモリ | 216,588 KB |
実行使用メモリ | 22,560 KB |
最終ジャッジ日時 | 2024-11-21 00:19:11 |
合計ジャッジ時間 | 33,527 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,636 KB |
testcase_01 | AC | 2 ms
13,640 KB |
testcase_02 | AC | 2 ms
16,160 KB |
testcase_03 | AC | 2 ms
13,632 KB |
testcase_04 | AC | 2 ms
13,636 KB |
testcase_05 | AC | 2 ms
21,920 KB |
testcase_06 | AC | 2 ms
13,640 KB |
testcase_07 | AC | 2 ms
13,636 KB |
testcase_08 | AC | 2 ms
13,636 KB |
testcase_09 | AC | 2 ms
22,436 KB |
testcase_10 | AC | 2 ms
13,640 KB |
testcase_11 | AC | 8 ms
13,636 KB |
testcase_12 | AC | 2 ms
13,636 KB |
testcase_13 | AC | 2 ms
22,432 KB |
testcase_14 | AC | 2 ms
13,632 KB |
testcase_15 | AC | 8 ms
22,560 KB |
testcase_16 | AC | 2 ms
13,632 KB |
testcase_17 | AC | 2 ms
13,636 KB |
testcase_18 | AC | 50 ms
13,640 KB |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 12 ms
6,816 KB |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
ソースコード
#define MOD_TYPE 2 #pragma region Macros #include <bits/stdc++.h> using namespace std; #if 1 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #if 0 #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/tag_and_trait.hpp> #include <ext/rope> using namespace __gnu_pbds; using namespace __gnu_cxx; template <typename T> using extset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #endif #if 0 #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; template <typename T> using smaller_queue = priority_queue<T, vector<T>, greater<T>>; constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr ld PI = acos(-1.0); constexpr ld EPS = 1e-7; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <typename T, typename U> constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept { is >> p.first >> p.second; return is; } template <typename T, typename U> constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion random_device seed_gen; mt19937_64 engine(seed_gen()); // -------------------------------------- using Matrix = map<array<int, 2>, int>; void matprod(Matrix &P, Matrix &A) { Matrix res; for (auto [k, v] : P) { auto [i, j] = k; for (auto [kk, vv] : A) { auto [ii, jj] = kk; if (j != ii) continue; res[{i, jj}] += v * vv; } } P = res; } void solve() { // 嘘解法?O(N^2) int n, k; cin >> n >> k; if (k == 0) { cout << 1 << "\n"; return; } Matrix A; rep(i, k) { int r, c; cin >> r >> c; r--, c--; A[{r, c}]++; } auto P = A; for (int i = 2; i <= n; i++) { matprod(P, A); if (i == 2 and P.size() > A.size()) { cout << -1 << "\n"; return; } if (P.size() == 0) { cout << i << "\n"; return; } } cout << -1 << "\n"; } int main() { solve(); }