結果

問題 No.429 CupShuffle
ユーザー beetbeet
提出日時 2018-07-30 14:34:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 167,292 KB
実行使用メモリ 6,492 KB
最終ジャッジ日時 2023-10-11 20:36:27
合計ジャッジ時間 3,056 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 9 ms
4,352 KB
testcase_11 AC 82 ms
6,276 KB
testcase_12 AC 77 ms
6,156 KB
testcase_13 AC 82 ms
6,492 KB
testcase_14 AC 81 ms
6,212 KB
testcase_15 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,k,x;
  cin>>n>>k>>x;
  x--;
  vector<Int> a(k),b(k);
  for(Int i=0;i<k;i++){
    char y;
    if(i!=x) cin>>a[i]>>b[i];
    else cin>>y>>y;
  }
  
  vector<Int> c(n),d(n);
  for(Int i=0;i<n;i++) cin>>c[i];
  iota(d.begin(),d.end(),0);

  for(Int i=0;i<k;i++){
    if(i==x) continue;
    a[i]--;b[i]--;
    swap(d[a[i]],d[b[i]]);
  }
  
  Int s=-1,t=-1;
  for(Int i=0;i<n;i++){
    c[i]--;
    if(d[i]!=c[i]) t=s,s=d[i];
  }
  
  for(Int i=k-1;i>x;i--)
    swap(d[a[i]],d[b[i]]);

  Int p=-1,q=-1;
  for(Int i=0;i<n;i++){
    if(s==d[i]) p=i;
    if(t==d[i]) q=i;
  }
  
  if(p>q) swap(p,q);
  cout<<p+1<<" "<<q+1<<endl;
  return 0;
}
0