結果
問題 |
No.590 Replacement
|
ユーザー |
![]() |
提出日時 | 2017-04-15 19:45:12 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 441 bytes |
コンパイル時間 | 685 ms |
コンパイル使用メモリ | 61,400 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-07-19 09:30:34 |
合計ジャッジ時間 | 5,264 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 TLE * 1 -- * 33 |
ソースコード
#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; int main(){ cin>>n; a=b=vi(n); for(int i=0;i<n;i++){ int t; cin>>t; a[t-1]=i; } for(int i=0;i<n;i++){ int t; cin>>t; b[t-1]=i; } ll res=0; for(int i=0;i<n;i++){ int x=i,y=i,num=0; do{ (res+=num)%=mod; x=a[x]; y=b[y]; num++; }while(x!=y); } cout<<res<<endl; }