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:38:44
2017-05-27 11:29:13
Task:Jonnesort
Sender:oispa opiskelupaikka tefyllä ;...;
Submission time:2017-05-27 11:38:44
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;

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

    
    int r = 1;
    for(int i = 0; i+k <= n; ++i){
            sort(a+i, a+i+k);
        }
        bool gg = true;
        for(int i = 0; i < n; ++i){
            if(a[i] != s[i]){
                gg = false;
                break;
            }
        }
        if(gg){
            cout << 1 << endl;
            return 0;
        }
      
        
    for(int i = 0; i < n; ++i)
        s[i] = a[i];
    while(true){
        for(int i = 0; i+k <= n; ++i){
            sort(a+i, a+i+k);
        }
        bool g = true;
        for(int i = 0; i < n; ++i){
            if(a[i] != s[i]){
                g = false;
                break;
            }
        }
         for(int i = 0; i < n; ++i)
        s[i] = a[i];
        r++;
        if(g){
            break;
        }
    }
    cout << r << endl;
    return 0;
}