結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー h_nosonh_noson
提出日時 2016-03-26 16:37:21
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,042 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 69,232 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-09 23:57:03
合計ジャッジ時間 7,685 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 109 ms
6,944 KB
testcase_04 AC 14 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0