제출 #805507

#제출 시각아이디문제언어결과실행 시간메모리
805507HaroldVemeno고대 책들 (IOI17_books)C++17
0 / 100
1 ms308 KiB
#include "books.h" #include <bits/stdc++.h> #ifdef GUDEB #define D(x) cerr << #x << ": " << (x) << '\n'; #define ifdeb if(true) #else #define D(x) ; #define ifdeb if(false) #endif #define all(x) begin(x), end(x) using namespace std; using ull = unsigned long long; using ll = long long; using pii = pair<int, int>; // #define int ll; struct N { int c; int i; friend bool operator < (const N& a, const N& b) { return a.c > b.c; } }; int n; ll ret = 0; priority_queue<N> q; bool vis[1000000]; long long minimum_walk(vector<int> p, int s) { n = p.size(); for(int i = 0; i < n; ++i) { if(p[i] == i) vis[i] = true; ret += abs(i - p[i]); } vis[s] = false; q.push({0, s}); while(!q.empty()) { N t = q.top(); q.pop(); D(t.i) D(t.c) if(vis[t.i]) continue; ret += 2*t.c; D(ret) vis[t.i] = true; q.push({0, p[t.i]}); { int ln = t.i+1; if(ln < n && ln == p[ln]) ++ln; if(ln != n) { q.push({ln - t.i, ln}); } } { int rn = t.i-1; if(rn >= 0 && rn == p[rn]) --rn; if(rn >= 0) { q.push({t.i - rn, rn}); } } } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...