結果
問題 | No.366 ロボットソート |
ユーザー |
![]() |
提出日時 | 2018-08-01 15:58:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 463 bytes |
コンパイル時間 | 1,526 ms |
コンパイル使用メモリ | 170,464 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-19 16:45:20 |
合計ジャッジ時間 | 2,039 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; //INSERT ABOVE HERE signed main(){ Int n,k; cin>>n>>k; vector<Int> a(n); for(Int i=0;i<n;i++) cin>>a[i]; Int ans=0; for(Int s=0;s<k;s++){ for(Int i=s;i<n;i+=k) for(Int j=s;j<i;j+=k) ans+=a[j]>a[i]; for(Int i=s;i<n;i+=k) for(Int j=s;j<i;j+=k) if(a[j]>a[i]) swap(a[i],a[j]); } if(!is_sorted(a.begin(),a.end())) ans=-1; cout<<ans<<endl; return 0; }