結果
問題 | No.326 あみだますたー |
ユーザー |
|
提出日時 | 2020-05-16 03:29:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 2,545 ms |
コンパイル使用メモリ | 195,256 KB |
最終ジャッジ日時 | 2025-01-10 12:19:04 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | int n,k; scanf("%d%d",&n,&k); | ~~~~~^~~~~~~~~~~~~~ main.cpp:12:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | int x; scanf("%d%*d",&x); x--; | ~~~~~^~~~~~~~~~~~ main.cpp:16:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | rep(i,n) scanf("%d",&g[i]), g[i]--; | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(n);i++)using namespace std;int main(){int n,k; scanf("%d%d",&n,&k);vector<int> p(n);iota(p.begin(),p.end(),0);rep(i,k){int x; scanf("%d%*d",&x); x--;swap(p[x],p[x+1]);}vector<int> g(n);rep(i,n) scanf("%d",&g[i]), g[i]--;vector<int> ans;rep(i,n){int t=find(g.begin(),g.end(),i)-g.begin();int j=find(p.begin(),p.end(),t)-p.begin();if(i<=j){for(int k=j-1;k>=i;k--){swap(p[k],p[k+1]);ans.emplace_back(k);}}else{for(int k=j;k<i;k++){swap(p[k],p[k+1]);ans.emplace_back(k);}}}printf("%lu\n",ans.size());for(int x:ans) printf("%d %d\n",x+1,x+2);return 0;}