CSES - Datatähti 2017 alku - Results
Submission details
Task:Järjestys
Sender:OulaK
Submission time:2016-10-03 21:40:45 +0300
Language:C++
Status:READY
Result:56
Feedback
groupverdictscore
#1ACCEPTED19
#2ACCEPTED37
#30
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.05 s2details
#3--3details

Code

#include <iostream>
#include <algorithm>
#include <vector>

int main() {

    int n;
    std::cin >> n;
    
    int str[n];
    std::vector<int> moves;

    for(int i = 0; i < n; i++)
        std::cin >> str[i];

    bool fin = false;
    while(!fin) {
        int s = str[0];
        int to = 0;

        if(s == n) to = n;
        
        else if(str[1] == s + 1) {
            int prev = 0;
            for(int i = 0; i < n; i++) {
                if(prev < str[i]) {
                    prev = str[i];    
                } else {
                    to = i;
                    break;    
                }

                if(i == n - 1) fin = true;
            }
        } else {
            for(int i = 2; i < n; i++) {
                if(str[i] == s + 1) {
                    to = i;
                    break;    
                }
            }
        }

        std::reverse(str, str + to);
        if(to != 0) moves.push_back(to);
    }

    std::cout << moves.size() << "\n";

    for(unsigned int c = 0; c < moves.size(); c++ /* heh */)
        std::cout << moves[c] << " ";
    std::cout << "\n";

    return 0;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
10
9 3 4 7 6 5 10 2 8 1

correct output
32
10 10 9 10 9 8 7 9 4 2 1 4 5 2...

user output
10
6 3 8 3 2 10 7 6 8 2 

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
650 716 982 41 133 1000 876 92...

correct output
3984
207 207 206 207 128 127 126 12...

user output
2202
988 477 174 466 864 765 882 82...

Test 3

Group: 3

Verdict:

input
100000
94703 47808 62366 31885 7091 8...

correct output
399956
98676 98676 98675 98676 62994 ...

user output
(empty)