結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー furafura
提出日時 2020-06-08 00:04:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 958 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 200,932 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-08-25 14:20:13
合計ジャッジ時間 31,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 231 ms
4,380 KB
testcase_12 AC 241 ms
4,376 KB
testcase_13 AC 208 ms
4,380 KB
testcase_14 AC 336 ms
4,380 KB
testcase_15 AC 22 ms
4,376 KB
testcase_16 AC 28 ms
4,376 KB
testcase_17 AC 33 ms
4,376 KB
testcase_18 AC 42 ms
4,376 KB
testcase_19 AC 47 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 73 ms
4,380 KB
testcase_23 AC 39 ms
4,376 KB
testcase_24 AC 664 ms
4,376 KB
testcase_25 AC 461 ms
4,376 KB
testcase_26 AC 338 ms
4,376 KB
testcase_27 TLE -
testcase_28 AC 3,146 ms
4,376 KB
testcase_29 AC 2,945 ms
4,376 KB
testcase_30 AC 2,431 ms
4,376 KB
testcase_31 AC 2,368 ms
4,376 KB
testcase_32 AC 2,362 ms
4,380 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

using namespace std;

class permutation{
	vector<int> f;
public:
	permutation(){}
	permutation(int n){
		f.resize(n);
		iota(f.begin(),f.end(),0);
	}
	permutation(const vector<int>& p):f(p){}

	permutation operator*(const permutation& p)const{
		int n=f.size();
		permutation res(n);
		rep(i,n) res.f[i]=f[p[i]];
		return res;
	}
	int operator[](int i)const{ return f[i]; }

	int size()const{ return f.size(); }

	void swap(int i,int j){ std::swap(f[i],f[j]); }

	friend permutation inverse(const permutation& p){
		int n=p.f.size();
		permutation res(n);
		rep(i,n) res.f[p.f[i]]=i;
		return res;
	}
};

int main(){
	int n,k; scanf("%d%d",&n,&k);
	permutation p(n);
	rep(i,k){
		int x; scanf("%d%*d",&x); x--;
		p.swap(x,x+1);
	}

	permutation q(n);
	for(int t=1;;t++){
		q=q*p;
		bool ok=true;
		rep(i,n) if(q[i]!=i) ok=false;
		if(ok){
			printf("%d\n",t);
			break;
		}
	}

	return 0;
}
0