답안 #585701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585701 2022-06-29T08:43:47 Z InternetPerson10 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 340 KB
#include "books.h"
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

vector<vector<int>> adj;
vector<int> dist;

long long minimum_walk(vector<int> p, int s) {
    ll tot = 0;
    int n = p.size();
    vector<bool> taken(n, false);
    int g = n;
    adj.resize(n);
    for(int i = 1; i < n; i++) {
        adj[i].push_back(i-1);
        adj[i-1].push_back(i);
    }
    for(int i = 0; i < n; i++) {
        if(!taken[i]) {
            adj.push_back(vector<int>());
            int x = i;
            int l = i, r = i;
            while(!taken[x]) {
                taken[x] = true;
                tot += abs(x - p[x]);
                x = p[x];
                l = min(l, x);
                r = max(r, x);
                adj[x].push_back(g);
            }
            for(int j = l; j <= r; j++) {
                adj[g].push_back(j);
            }
            g++;
        }
    }
    dist.resize(g, 1e9 + 7);
    int best = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push({0, s});
    while(pq.size()) {
        auto p = pq.top();
        pq.pop();
        int len = p.first, x = p.second;
        if(len > dist[x]) continue;
        best = max(best, len);
        for(int ch : adj[x]) {
            int goLength;
            if(max(ch, x) < n) {
                goLength = len + 1;
            }
            else {
                goLength = len;
            }
            if(dist[ch] <= goLength) continue;
            dist[ch] = goLength;
            pq.push({goLength, ch});
        }
    }
	return tot + 2 * best;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '5920', found: '5922'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -