結果

問題 No.590 Replacement
ユーザー Pulmn
提出日時 2017-04-14 22:00:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 472 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 61,068 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-19 09:27:48
合計ジャッジ時間 4,419 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 TLE * 1 -- * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef long long ll;

const ll mod=1e9+7;

int n;
vi a,b;

ll f(int x,int y){
	for(int i=0;i<n*n+10;i++){
		if(x==y) return i;
		x=a[x];
		y=b[y];
	}
	return 0;
}

int main(){
	cin>>n;
	a=b=vi(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
		b[i]--;
	}
	ll res=0;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) (res+=f(i,j))%=mod;
	cout<<res<<endl;
}
0