Submission #1061425

# Submission time Handle Problem Language Result Execution time Memory
1061425 2024-08-16T08:57:03 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 base = 0;
    for (int i = 0; i < n; i++) base += abs(p[i] - i);

    vector<bool> vst(n);
    ll numCyc = -1;
    for (int i = 0; i < n; i++) {
        if (vst[i]) continue;
        numCyc++;
 
        ll cur = i;
        do {
            cur = p[cur];
            vst[cur] = true;
        } while (cur != i);
    }

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