結果
問題 | No.326 あみだますたー |
ユーザー |
![]() |
提出日時 | 2016-03-03 18:58:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 880 bytes |
コンパイル時間 | 430 ms |
コンパイル使用メモリ | 43,608 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 23:27:55 |
合計ジャッジ時間 | 1,646 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
コンパイルメッセージ
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;}