Submission details
Task:Lista
Sender:Teuro
Submission time:2025-11-08 09:57:51 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails

Code

#include <iostream>
#include <numeric>
#include <list>
#include <algorithm>

std::list<int> luvut;
std::list<int> haettavat;

int n, m, h;

int laske_kustannus(const std::list<int>& luvut, const std::list<int>& haettavat) {
    int kustannus = 0;

    for (int h : haettavat) {
        int askelia = 0;
        for (int l : luvut) {
            askelia++;
            if (l == h) {
                kustannus += askelia;
                break;
            }
        }
    }

    return kustannus;
}

int main() {
    std::cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        luvut.push_back(i);
	}
	
	while (std::cin >> h) {
		haettavat.push_back(h);
    }
	
    for (int h : haettavat) {
        auto it = std::find(luvut.begin(), luvut.end(), h);
        if (it != luvut.end()) {
            luvut.erase(it);
            luvut.push_front(h);
        }
    }

    int kustannus_jalkeen = laske_kustannus(luvut, haettavat);
    std::cout << kustannus_jalkeen << std::endl;

    for (int x : luvut) {
        std::cout << x << " ";
    }
    
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
1 1
1

correct output
1

user output
1

Test 2

Verdict: ACCEPTED

input
100 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1000
1 100 99 98 97 96 95 94 93 92 ...

user output
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 3

Verdict:

input
100 1000
1 2 2 2 1 1 1 1 1 1 1 1 1 2 1 ...

correct output
1488
1 2 100 99 98 97 96 95 94 93 9...

user output
1512
2 1 3 4 5 6 7 8 9 10 11 12 13 ...

Test 4

Verdict:

input
100 1000
7 8 2 4 8 3 3 10 9 7 7 6 8 7 2...

correct output
5109
3 8 7 5 1 6 2 4 9 10 100 99 98...

user output
5404
6 5 8 3 4 10 2 9 1 7 11 12 13 ...

Test 5

Verdict:

input
100 1000
23 85 3 99 63 79 38 37 67 28 7...

correct output
41714
57 38 63 62 93 85 95 81 79 61 ...

user output
47419
82 43 22 99 77 80 34 17 49 1 5...