Submission #81151

# Submission time Handle Problem Language Result Execution time Memory
81151 2018-10-24T02:40:19 Z Tuhi Ancient Books (IOI17_books) C++14
0 / 100
2 ms 640 KB
#include <bits/stdc++.h>

using namespace std;
const int Nmax = 1e6 + 10;

int n, s, l, r, p[Nmax];

bool ordered(vector<int> a) {
    for(int i = 0; i < n - 1; ++i) {
        if (a[i] > a[i + 1]) return false;
    }
    return true;
}

int solve_1(vector<int> p, int pos) {
    int l = 0, r = n - 1, res = 0;
    while(!ordered(p)) {
        while(p[r] == r) --r;
        while(p[l] == l) ++l;
        for( ; pos < r; ++pos) {
            if (p[pos + 1] < p[pos]) swap(p[pos + 1], p[pos]);
            ++res;
        }
        if (ordered(p)) break;
        for( ; pos > l; --pos) {
            if (p[pos - 1] > p[pos]) swap(p[pos - 1], p[pos]);
            ++res;
        }
    }
    return res + abs(pos - s);
}

int solve_2(vector<int> p, int pos) {
    int l = 0, r = n - 1, res = 0;
    while(!ordered(p)) {
        while(p[r] == r) --r;
        while(p[l] == l) ++l;
        for( ; pos > l; --pos) {
            if (p[pos - 1] > p[pos]) swap(p[pos - 1], p[pos]);
            ++res;
        }
        if (ordered(p)) break;
        for( ; pos < r; ++pos) {
            if (p[pos + 1] < p[pos]) swap(p[pos + 1], p[pos]);
            ++res;
        }
    }
    return res + abs(pos - s);
}

int64_t minimum_walk(vector<int> a, int s) {
    n = a.size();
    int tmp1 = solve_1(a, s), tmp2 = solve_2(a, s);
    return min(tmp1, tmp2);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 400 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 400 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 400 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 640 KB 3rd lines differ - on the 1st token, expected: '3304', found: '5517'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 400 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -