結果
問題 | No.326 あみだますたー |
ユーザー | Ysmr_Ry |
提出日時 | 2016-03-03 18:58:49 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 880 bytes |
コンパイル時間 | 395 ms |
コンパイル使用メモリ | 43,992 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-25 12:03:37 |
合計ジャッジ時間 | 1,435 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 3 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:58: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=] 58 | 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 ); | ~~~~~^~~~~~~~~~~~
ソースコード
// 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[i+1] = A; } rep( i, N ) ord[i] = f[ord[i]]; bool upd = true; while( upd ) { upd = false; rep( i, N-1 ) { if( ord[i] > ord[i+1] ) { std::swap( ord[i], ord[i+1] ); ps.push_back( P( i+1, i+2 ) ); upd = true; } } } printf( "%d\n", ps.size() ); rep( i, ps.size() ) printf( "%d %d\n", ps[i].first, ps[i].second ); return 0; }