Submission #637521

# Submission time Handle Problem Language Result Execution time Memory
637521 2022-09-02T11:14:48 Z boris_mihov Ancient Books (IOI17_books) C++17
0 / 100
2000 ms 340 KB
#include "books.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 1000000 + 10;
const int INF  = 1e9;

int a[MAXN];
int b[MAXN];
int res[MAXN];
int perm[MAXN], n, s;

llong check()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        b[i] = a[i];
    }

    perm[n + 1] = s;
    llong ans = 0;

    for (int i = 1 ; i <= n ; ++i)
    {
        std::swap(a[perm[i]], a[perm[i + 1]]);
        ans += abs(perm[i] - perm[i + 1]);
    }

    bool sorted = true;
    for (int i = 1 ; i <= n ; ++i)
    {
        if (a[i] != i) sorted = false;
        a[i] = b[i];
    }

    if (!sorted) return INF;
    return ans;
}

llong minimum_walk(std::vector <int> P, int S) 
{
    n = P.size(); s = S + 1;
    for (int i = 1 ; i <= n ; ++i)
    {
        a[i] = P[i-1] + 1;
    }

    std::iota(perm + 1, perm + 1 + n, 1);
    llong ans = INF;
    do
    {
        ans = std::min(ans, check());
    } while(std::next_permutation(perm + 1, perm + 1 + n));

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '1000000000'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '1000000000'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '1000000000'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2058 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '1000000000'
3 Halted 0 ms 0 KB -