Submission #54102

# Submission time Handle Problem Language Result Execution time Memory
54102 2018-07-02T10:51:35 Z chpipis Ancient Books (IOI17_books) C++11
0 / 100
3 ms 648 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> temp, segs;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (visit[i]) continue;
        int j = i;
        int mx = j;
        while (!visit[j]) {
            mx = max(mx, j);
            visit[j] = true;
            ans += abs(j - p[j]);
            j = p[j];
        }
        temp.pb(mp(i, mx));
    }
    segs.pb(temp[0]);
    for (auto it : temp) {
        if (it.fi < segs.back().se)
            segs.back().se = max(segs.back().se, it.se);
        else
            segs.pb(it);
    }
    int sz = (int)segs.size();
    for (int i = 0; i < sz - 1; i++) {
        ans += (segs[i + 1].fi - segs[i].se) * 2;
    }
    return ans;
}


# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Incorrect 2 ms 616 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Incorrect 2 ms 616 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Incorrect 2 ms 616 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 648 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 3 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Incorrect 2 ms 616 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -