Submission #1061487

# Submission time Handle Problem Language Result Execution time Memory
1061487 2024-08-16T09:51:07 Z Zicrus Ancient Books (IOI17_books) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

typedef long long ll;

ll minimum_walk(vector<int> p, int s) {
    ll n = p.size();
	ll res = 0;
    for (int i = 0; i < n; i++) res += abs(p[i] - i);

    vector<bool> vst(n);
    vector<vector<ll>> cyc;
    vector<ll> mxCyc;
    for (int i = 0; i < n; i++) {
        if (vst[i] || p[i] == i) continue;
        cyc.push_back(vector<ll>());
        mxCyc.push_back(i);
 
        ll cur = i;
        do {
            cyc.back().push_back(cur);
            mxCyc.back() = max(mxCyc.back(), cur);
            cur = p[cur];
            vst[cur] = true;
        } while (cur != i);
    }
    ll m = cyc.size();

    ll mx = 0;
    for (int i = 1; i < m; i++) {
        mx = max(mx, mxCyc[i-1]);
        res += 2*max(0ll, cyc[i][0] - mx);
    }
    mx = max(mx, mxCyc.back());
    if (s < cyc[0][0]) res += 2*(cyc[0][0] - s);
    if (s > mx) res += 2*(s - mx);

    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 0 ms 348 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 0 ms 348 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 0 ms 348 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 0 ms 348 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -