Submission #395676

# Submission time Handle Problem Language Result Execution time Memory
395676 2021-04-28T18:04:37 Z blue Ancient Books (IOI17_books) C++17
0 / 100
1 ms 284 KB
#include "books.h"
#include <vector>
#include <cmath>
using namespace std;

/*
Permutations form cycles, we can efficiently go through an entire cycle.

If we want to go from u in cycle(u) to v in cycle(v), and we want to sort cycle C in the middle, we can
do so in length(C) + min{c in C, |u-c| + |c-v|}

Let R be a cycle such that min(R) is as large as possible.
*/


long long minimum_walk(vector<int> p, int s)
{
    long long res = 0;
    int n = p.size();
    vector<int> occ(n, 0);

    int D = 0;
    for(int i = 0; i < n; i++)
    {
        res += abs(p[i] - i);
        if(occ[i]) continue;
        D = i;
        occ[i] = 1;
        for(int j = p[i]; j != i; j = p[j])
        {
            occ[j] = 1;
        }
    }
    res += 2*D;
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 284 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -