Submission #581723

# Submission time Handle Problem Language Result Execution time Memory
581723 2022-06-23T05:00:11 Z alirezasamimi100 Ancient Books (IOI17_books) C++17
0 / 100
1 ms 296 KB
#include "books.h"
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second

using namespace std;

using ll = long long int;
using pll = pair<ll, ll>;
using pii = pair<int, int>;

const int inf = 1.05e9;
const ll INF = 1e18;

ll minimum_walk(vector<int> p, int s) {
    ll ans = 0, mn;
    int n = p.size();
    int f[n];
    memset(f, 0, sizeof f);
    vector<pii> wtf;
    for(int i = 0; i < n; i++){
        if(f[i]) continue;
        int ml = inf, mr = inf;
        for(int j = i; !f[j]; j = p[j]){
            f[j] = 1;
            ans += abs(j - p[j]);
            if(j <= s) ml = min(ml, s - j);
            if(j >= s) mr = min(mr, j - s);
        }
        wtf.pb({ml, mr});
    }
    int k = wtf.size();
    int pm[k];
    sort(wtf.begin(), wtf.end());
    pm[k - 1] = wtf[k - 1].S;
    for(int i = k - 2; i >= 0; i--){
        pm[i] = max(pm[i + 1], wtf[i].S);
    }
    mn = min(pm[0], wtf[k - 1].F);
    for(int i = 0; i < k - 1; i++) mn = min(mn, (ll)wtf[i].F + pm[i + 1]);
    return ans + 2 * mn;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 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 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 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 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 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 1 ms 296 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 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -