結果
問題 | No.101 ぐるぐる!あみだくじ! |
ユーザー |
![]() |
提出日時 | 2016-03-26 16:37:21 |
言語 | C++11 (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,042 bytes |
コンパイル時間 | 772 ms |
コンパイル使用メモリ | 68,000 KB |
実行使用メモリ | 8,448 KB |
最終ジャッジ日時 | 2024-10-02 00:54:06 |
合計ジャッジ時間 | 7,771 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 11 TLE * 1 -- * 25 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP(i,n,0) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 100000000 typedef long long ll; int n; void mult(vector<vector<int>> a, vector<vector<int>> b, vector<vector<int>>& c) { int i, j, k; rep (i,n) rep (j,n) { c[i][j] = 0; rep (k,n) { c[i][j] += a[i][k] * b[k][j]; } } } int main() { int i, k; vector<vector<int>> ini, mat; cin >> n >> k; ini.resize(n); mat.resize(n); rep (i,n) { ini[i].resize(n); ini[i][i] = 1; mat[i].resize(n); mat[i][i] = 1; } rep (i,k) { int x, y; cin >> x >> y; swap(ini[x-1],ini[y-1]); } bool ok; int ans = 0; do { ok = true; mult(ini,mat,mat); rep (i,n) ok &= mat[i][i] == 1; ans++; } while (!ok); cout << ans << endl; return 0; }