結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー fura
提出日時 2020-06-08 00:04:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 958 bytes
コンパイル時間 2,497 ms
コンパイル使用メモリ 194,668 KB
最終ジャッジ日時 2025-01-11 00:00:34
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 TLE * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |         int n,k; scanf("%d%d",&n,&k);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:41:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |                 int x; scanf("%d%*d",&x); x--;
      |                        ~~~~~^~~~~~~~~~~~

ソースコード

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