Submission #69616

# Submission time Handle Problem Language Result Execution time Memory
69616 2018-08-21T10:05:47 Z aquablitz11 Ancient Books (IOI17_books) C++14
0 / 100
3 ms 476 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1e9;

ll minimum_walk(vector<int> p, int s)
{
    int n = p.size();
    vector<pll> li;
    ll dist = 0;
    for (int i = 0; i < n; ++i) {
        if (p[i] == -1) continue;
        int u = i;
        ll l = -INF, r = INF;
        do {
            if (u <= s) l = max(l, (ll)u);
            if (u >= s) r = min(r, (ll)u);
            int v = p[u];
            dist += abs(u-v);
            p[u] = -1;
            u = v;
        } while (u != i);
        li.emplace_back(s-l, r-s);
    }
    sort(li.begin(), li.end());
    ll mx = 0, ans = INF*INF;
    for (int i = li.size()-1; i >= 0; --i) {
        ans = min(ans, li[i].first + mx);
        mx = max(mx, li[i].second);
    }
    ans = min(ans, mx);

	return dist+2*ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Incorrect 2 ms 476 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 3 ms 340 KB Output is correct
2 Incorrect 2 ms 476 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 3 ms 340 KB Output is correct
2 Incorrect 2 ms 476 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 3 ms 476 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4734'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Incorrect 2 ms 476 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -