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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:52:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < moves.size(); i++) cout << moves[i] << " ";
                                    ^
input/code.cpp: In function 'void print(std::vector<int>*)':
input/code.cpp:73:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < (*list_p).size(); i++)
                                        ^

Code

#include <iostream>
#include <vector>

using namespace std;

// prototypes
int swap(vector<int> *list_p, int n);
void print(vector<int> *list_p);

int main(void)
{
    // variables
    int n;
    int m;
    vector<int> list;
    vector<int> moves;

    // populate list
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> m;
        list.push_back(m);
    }

    // locate 1 and move to to correct position
    //print(&list);
    for (int i = 0; i < n; i++)
    {
        if (list[i] == 1)
        {
            moves.push_back(swap(&list, i));
        }
    }
    //print(&list);

    for (int i = n; i > 1; i--)
    {
        for (int j = 0; j < n; j++)
        {
            if (list[j] == i)
            {
                moves.push_back(swap(&list, j-1));
                moves.push_back(swap(&list, j));
                moves.push_back(swap(&list, 1));
                continue;
            }
        }
    }

    cout << moves.size() << '\n';
    for (int i = 0; i < moves.size(); i++) cout << moves[i] << " ";
    //cout << endl;
    //for (int i = 0; i < list.size(); i++) cout << list[i] << " ";
    //cout << endl;
    return 0;
}

int swap(vector<int> *list_p, int k)
{
    int c = k/2;
    for (int i = 0; i <= c; i++)
    {
        int tmp = (*list_p)[i];
        (*list_p)[i] = (*list_p)[k-i];
        (*list_p)[k-i] = tmp;
    }
    return k+1;
}

void print(vector<int> *list_p)
{
    for (int i = 0; i < (*list_p).size(); i++)
    {
        cout << (*list_p)[i] << " ";
    }
    cout << endl;
}

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
28
10 3 4 2 9 10 2 3 4 2 7 8 2 7 ...

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
2998
207 201 202 2 111 112 2 77 78 ...

Test 3

Group: 3

Verdict:

input
100000
94703 47808 62366 31885 7091 8...

correct output
399956
98676 98676 98675 98676 62994 ...

user output
(empty)