結果

問題 No.326 あみだますたー
ユーザー Ysmr_RyYsmr_Ry
提出日時 2016-03-03 18:44:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 800 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 43,836 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 19:41:25
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<std::pair<int, int> >::size_type’ {aka ‘long unsigned int’} [-Wformat=]
   49 |         printf( "%d\n", ps.size() );
      |                  ~^     ~~~~~~~~~
      |                   |            |
      |                   int          std::vector<std::pair<int, int> >::size_type {aka long unsigned int}
      |                  %ld
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf( "%d%d", &N, &K );
      |         ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                 scanf( "%d%d", &X, &Y );
      |                 ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |                 scanf( "%d", &A );
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

diff #

// yukicoder 326 (http://yukicoder.me/problems/905)
#include<cstdio>
#include<algorithm>
#include<numeric>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)

typedef std::pair<int, int> P;

const int MAX_K = 6000, MAX_N = 100;

int N, K;

int ord[MAX_N], f[MAX_N+1];

std::vector<P> ps;

int main()
{
	scanf( "%d%d", &N, &K );

	std::iota( ord, ord+N, 1 );

	rep( i, K )
	{
		int X, Y;
		scanf( "%d%d", &X, &Y );

		std::swap( ord[X-1], ord[Y-1] );
	}
	rep( i, N )
	{
		int A;
		scanf( "%d", &A );
		f[A] = i;
	}
	rep( i, N )
		ord[i] = f[ord[i]];

	rep( i, N ) rep( j, i )
	{
		if( ord[j] > ord[i] )
		{
			std::swap( ord[j], ord[i] );
			ps.push_back( P( j+1, i+1 ) );
		}
	}

	printf( "%d\n", ps.size() );
	rep( i, ps.size() )
		printf( "%d %d\n", ps[i].first, ps[i].second );

	return 0;
}
0