結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー codershifthcodershifth
提出日時 2015-08-04 23:48:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,507 bytes
コンパイル時間 1,219 ms
コンパイル使用メモリ 147,872 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-25 01:11:49
合計ジャッジ時間 5,782 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class GruGruAmidakuji {
public:
    void solve(void) {
            int N,K;
            cin>>N>>K;

            // F[i] := i を入力するとあみだくじをたどって F[i] に到達する
            vector<int> F(N);
            iota(RANGE(F),0);

            REP(i,K)
            {
                int x,y;
                cin>>x>>y;
                --x,--y;
                // 棒があるとそこで入力が交換される
                swap(F[x],F[y]);
            }
            // F^s(x) = F*F*...*F(x)=x (all x) なる最小の s を探せば良い
            vector<int> in(F);
            vector<int> out(N);
            FOR(s,1,100000)
            {
                bool ok = true;
                REP(i,N)
                {
                    if (in[i]!=i)
                        ok = false;
                    out[i] = F[in[i]];
                }
                if (ok)
                {
                    cout<<s<<endl;
                    return;
                }
                in = out;
            }
            assert(false);
            return;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new GruGruAmidakuji();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0