CSES - Datatähti 2017 alku - Results
Submission details
Task:Järjestys
Sender:3isagreatnumber
Submission time:2016-10-05 15:46:55 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.05 s1details
#20.05 s2details
#3--3details

Compiler report

input/code.cpp: In function 'void print(std::vector<int>*)':
input/code.cpp:67: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
void swap(vector<int> *list_p, int n);
void print(vector<int> *list_p);

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

    // 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) swap(&list, i);
    }
    //print(&list);

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

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

void swap(vector<int> *list_p, int k)
{
    cout << k+1 << " ";
    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;
    }
}

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:

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

Test 2

Group: 2

Verdict:

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

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

user output
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)