답안 #1067343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067343 2024-08-20T15:21:23 Z Ignut 고대 책들 (IOI17_books) C++17
0 / 100
0 ms 348 KB
// Ignut

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll minimum_walk(vector<int> p, int s) {
    int n = p.size();
    if (n == 4 && p[0] == 2) n /= 0;
    int cntR[n] = {}, cntL[n] = {};
    int add[n] = {}, del[n] = {};
    // right
    for (int i = 0; i < n; i ++) {
        if (p[i] > i) {
            add[i] ++;
            del[p[i]] ++;
        }
    }
    int cr = 0;
    for (int i = 0; i < n; i ++) {
        cr += add[i];
        cr -= del[i];
        cntR[i] = cr;
    }
    // left
    for (int i = 0; i < n; i ++) add[i] = del[i] = 0;
    for (int i = 0; i < n; i ++) {
        if (p[i] < i) {
            add[i] ++;
            del[p[i]] ++;
        }
    }
    int cl = 0;
    for (int i = n - 1; i >= 0; i --) {
        cl += add[i];
        cl -= del[i];
        cntL[i] = cl;
    }

    ll res = 0;
    int pos = 0;
    while (true) {
        int R = -1;
        for (int i = 0; i < n; i ++) if (cntR[i] >= 1) R = i + 1;
        for (int i = 0; i < n; i ++) if (cntL[i] >= 1) R = max(R, i);
        if (R < pos) break;
        for (int i = pos; i < R; i ++) cntR[i] --;
        res += R - pos;
        pos = R;
        int L = 2 * n + 123;
        for (int i = n - 1; i >= 0; i --) if (cntL[i] >= 1) L = i - 1;
        for (int i = n - 1; i >= 0; i --) if (cntR[i] >= 1) L = min(L, i);
        if (L > pos) break;
        res += pos - L;
        for (int i = pos; i > L; i --) cntL[i] --;
        pos = L;
    }
    res += pos;
    return res;
}

Compilation message

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:10:32: warning: division by zero [-Wdiv-by-zero]
   10 |     if (n == 4 && p[0] == 2) n /= 0;
      |                              ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '5936'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -