답안 #718568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718568 2023-04-04T10:46:45 Z Jarif_Rahman 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

ll minimum_walk(vector<int> p, int s){
    int n = p.size();
    ll ans = 0;

    vector<int> cycle_id(n, -1);
    int k = 0;
    for(int i = 0; i < n; i++){
        if(cycle_id[i] != -1) continue;
        int x = p[i];
        cycle_id[i] = k;
        ans+=abs(i-x);
        while(x != i){
            cycle_id[x] = k;
            ans+=abs(p[x]-x);
            x = p[x];
        }
        k++;
    }

    vector<int> cnt(k, 0);
    for(int i = 0; i < n; i++) cnt[cycle_id[i]]++;
    vector<bool> nested(k, 0);
    set<int> st;
    for(int i = 0; i < n; i++){
        st.insert(cycle_id[i]);
        if(st.size() > 2) nested[cycle_id[i]] = 1;
        cnt[cycle_id[i]]--;
        if(cnt[cycle_id[i]] == 0) st.erase(cycle_id[i]);
    }

    ans+=k-1;
    for(int i = 1; i < k; i++) if(!nested[i]) ans++;
    return ans;
}
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4110'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -