結果

問題 No.326 あみだますたー
ユーザー fura
提出日時 2020-05-16 03:25:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 197,332 KB
最終ジャッジ日時 2025-01-10 12:18:52
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 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]--;
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#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(t,n){
		int i=find(g.begin(),g.end(),t)-g.begin();
		int j=find(p.begin(),p.end(),i)-p.begin();
		for(int k=j-1;k>=0;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;
}
0