Submission #708116

# Submission time Handle Problem Language Result Execution time Memory
708116 2023-03-11T05:50:17 Z Cyanmond Ancient Books (IOI17_books) C++17
0 / 100
1 ms 212 KB
#include "books.h"
#include <bits/stdc++.h>

using i64 = long long;

void chmax(i64 &a, i64 b) {
    if (a < b) a = b;
}

long long minimum_walk(std::vector<int> p, int s) {
    const int n = (int)p.size();
    std::vector<i64> imos(n);
    for (int i = 0; i < n; ++i) {
        int a = i, b = p[i];
        if (a > b) std::swap(a, b);
        ++imos[a];
        --imos[b];
    }
    for (int i = 0; i < n - 1; ++i) imos[i + 1] += imos[i];
    i64 baseCost = std::accumulate(imos.begin(), imos.end(), 0ll);
    i64 x = 0, c = 0;
    for (int i = 1; i < n; ++i) {
        if (imos[i] == 0) {
            ++c;
        }
        if (imos[i] != 0) {
            x += 2 * c;
            c = 0;
        }
    }
    return baseCost + 2 * x;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 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 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -