結果

問題 No.366 ロボットソート
ユーザー Lay_ecLay_ec
提出日時 2016-04-30 00:07:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 817 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 82,948 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 06:20:15
合計ジャッジ時間 1,203 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;


const long long mod=1000000007; 

int a[100000];

int main()
{
	int n,k;
	cin>>n>>k;
	
	vector<int> a(n);
	for(int i=0;i<n;i++) cin>>a[i];

	int res=0;
	for(int i=0;i<n;i++){
		int idx=i;
		for(int j=i+1;j<n;j++){
			if(a[idx]>a[j]) idx=j;
		}
		//cout<<i<<" "<<idx<<endl;
		if(i==idx) break;
		if( (idx-i)%k==0 ){
			
			while(true){
				swap(a[idx],a[idx-k]);
				res++;
				if(idx-k==i) break;
				idx-=k;
			}
			
		}else{
			break;
		}
		
	}
	
	if(is_sorted(a.begin(),a.end())) cout<<res<<endl;
	else cout<<-1<<endl;
	
    return 0;
}
0