結果
問題 |
No.2289 順列ソート
|
ユーザー |
![]() |
提出日時 | 2025-10-04 16:26:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 414 bytes |
コンパイル時間 | 1,984 ms |
コンパイル使用メモリ | 194,996 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-10-04 16:27:02 |
合計ジャッジ時間 | 2,896 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
コンパイルメッセージ
In file included from /usr/include/c++/13/bits/stl_pair.h:61, from /usr/include/c++/13/bits/stl_algobase.h:64, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from main.cpp:1: In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = int]’, inlined from ‘int main()’ at main.cpp:29:7: /usr/include/c++/13/bits/move.h:198:11: warning: ‘nowx’ may be used uninitialized [-Wmaybe-uninitialized] 198 | __a = _GLIBCXX_MOVE(__b); | ^ main.cpp: In function ‘int main()’: main.cpp:20:37: note: ‘nowx’ was declared here 20 | int minx=0x3f3f3f3f,nowx; | ^~~~
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; if(n==1) { cout<<0<<endl; return 0; } int a[n+1]; int ans=0; for(int i=1;i<=n;i++) { cin>>a[i]; } int cnt=0; for(int i=1;i<=n;i++) { int minx=0x3f3f3f3f,nowx; for(int j=i;j<=n;j++) { if(a[j]<minx) { minx=a[j]; nowx=j; } } swap(a[i],a[nowx]); if(i!=nowx)cnt++; } cout<<cnt<<endl; return 0; }