結果

問題 No.101 ぐるぐる!あみだくじ!
コンテスト
ユーザー fura
提出日時 2020-06-08 00:04:22
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 958 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,381 ms
コンパイル使用メモリ 213,364 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2026-06-10 14:16:53
合計ジャッジ時間 21,263 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 33 TLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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