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:30:37
Task:Jonnesort
Sender:KnowYourArchitecture
Submission time:2017-05-27 11:30:37
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;
int a[10000];
int b[10000];

int main() {
    int k, n;
    cin >> n >> k;

    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    for (int r = 1; ; r++) {
        for (int i = 0; i < n; i++)
            b[i] = a[i];
        
        for (int i = 0; i+k <= n; i++) {
            sort(&a[i], &a[i+k]);
        }
        
        bool ready = true;
        for (int i = 0; i < n; i++)
            ready &= a[i] == b[i];
        
        if (ready) {
            cout << r << endl;
            return 0;
        }
    }
    
    return 0;
}