Submission #54098

# Submission time Handle Problem Language Result Execution time Memory
54098 2018-07-02T10:29:32 Z chpipis Ancient Books (IOI17_books) C++11
0 / 100
3 ms 840 KB
#include "books.h"
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;

const int MAX_N = 1e6 + 5;

bitset<MAX_N> visit;
vector<int> p, from;
int n;

ll minimum_walk(vector<int> _p, int s) {
    assert(s == 0);
    p = _p;
    n = (int)p.size();
    from.resize(n);
    for (int i = 0; i < n; i++)
        from[p[i]] = i;
    visit.reset();
    vector<ii> segs;
    vector<ll> val;
    for (int i = 0; i < n; i++) {
        if (visit[i]) continue;
        int j = i;
        int mx = j;
        val.pb(0);
        while (!visit[j]) {
            mx = max(mx, j);
            visit[j] = true;
            val.back() += abs(j - p[j]);
            j = p[j];
        }
        segs.pb(mp(i, mx));
    }
    ll ans = 0;
    for (auto it : val) ans += it;
    int sz = (int)segs.size();
    for (int i = 0, j; i < sz; i = j) {
        j = i;
        int mx = segs[i].se;
        while (j < sz && segs[j].fi <= mx) {
            mx = max(mx, segs[j].se);
            j++;
        }
        ans += mx + 1 - from[segs[i].fi];
    }
    return ans;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 452 KB Output is correct
3 Incorrect 2 ms 600 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 376 KB Output is correct
2 Correct 2 ms 452 KB Output is correct
3 Incorrect 2 ms 600 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 376 KB Output is correct
2 Correct 2 ms 452 KB Output is correct
3 Incorrect 2 ms 600 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 Runtime error 3 ms 840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 452 KB Output is correct
3 Incorrect 2 ms 600 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -