Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 11:16:44
Task:Jonnesort
Sender:Ace of Spades
Submission time:2017-05-27 11:16:44
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
using namespace std;
const int MN = 1001;
int t[MN];
int t2[MN];
int main() {
    int n,k;
    cin>>n>>k;
    for(int i = 0; i < n; ++i) {
	cin>>t[i];
    }
    for(int i = 0; i <= n; ++i) {
	memcpy(t2, t, sizeof t);
	for(int j = 0; j+k-1 < n; ++j) {
	    sort(t+j, t+j+k);
	}
	/*
	for(int j = 0; j < n; ++j) {
	    cout<<t[j]<<' ';
	}
	cout<<'\n';
	*/
	int ok = 1;
	for(int j = 0; j < n; ++j) {
	    if(t2[j] != t[j]) {
		ok = 0;
		break;
	    }
	}
	if(ok) {
	    cout<<i+1<<endl;
	    return 0;
	}
    }
}