답안 #335696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335696 2020-12-13T17:46:49 Z couplefire 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 512 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

long long minimum_walk(vector<int> p, int s) {
    int n = p.size();
    vector<bool> visited(n, 0);
    vector<vector<int>> cycles;
    long long ans = 0;
    for(int i = 0; i<n; i++) ans += abs(p[i]-i);
    for(int i = 0; i<n; i++){
        if(visited[i]) continue;
        cycles.push_back({});
        int j = i;
        while(!visited[j]){
            visited[j] = 1;
            cycles.back().push_back(j);
            j = p[j];
        }
    }
    int leftMost = 0;
    for(auto x : cycles){
        if(x.size() == 1) continue;
        int mi = n;
        for(auto y : x) mi = min(mi, y);
        leftMost = max(leftMost, mi);
    }
	return ans+2ll*leftMost;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4728'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -