結果

問題 No.366 ロボットソート
コンテスト
ユーザー Thái Sơn Nguyễn
提出日時 2026-02-10 17:18:28
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 932 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 963 ms
コンパイル使用メモリ 110,804 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-10 17:18:31
合計ジャッジ時間 2,067 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <ctime>
#include <map>
using namespace std;

#define fi first
#define se second
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)

const long long mod = 1e9 + 7;
const long long mod1 = 1e9 + 4321, mod2 = 1e9 + 321;
const long long MAXN = 2e5 + 5;
const long long inf = 1e18;
//---------------------------------------------------
long long n, k, a[MAXN], cnt;
int main() {
	cin >> n >> k;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
	}
	for(int j = 1; j <= n; j ++)//day n so xuong.
	{
		for(int i = 1; i <= n - k; i ++)//cong dung bubble sort
		{
			if(a[i] > a[i + k])
			{
				swap(a[i], a[i + k]);
				//swap bo nho.
				cnt ++;
			}
		}
	}
	for(int i = 1; i < n; i ++)
	{
		if(a[i] > a[i + 1])//xet cai trc do la du(do co bac cau)
		{
			cnt = -1;
			break;
		}
	}
	cout << cnt;
    cerr << "Time elapsed: " << TIME << " s.\n";
    return 0;
}
0