結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー koyopro
提出日時 2015-10-01 23:50:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 711 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 162,036 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-19 19:01:47
合計ジャッジ時間 20,952 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 33 TLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(int i=0; i<(n); i++)

int N,K;
bool isok(vector<int> a) {
    REP(i,a.size()) {
        if (a[i] != i) return false;
    }
    return true;
}
signed main()
{
    cin >> N>>K;
    vector<int> amida(N);
    REP(i,N) amida[i] = i;
    vector<int> x(K);
    int y;
    REP(i,K) {
        cin >> x[i] >> y;
        swap(amida[x[i]-1], amida[x[i]]);
    }
    int cnt = 0;
    vector<int> tmp(N);
    REP(i,N) tmp[i] = i;
    while(true) {
        cnt++;
        vector<int> tmp2(N);
        REP(i,N) {
            tmp2[i] = tmp[amida[i]];
        }
        if (isok(tmp2)) break;
        tmp = tmp2;
    }
    cout << cnt << endl;
    return 0;
}
0