Submission #431788

#TimeUsernameProblemLanguageResultExecution timeMemory
431788yuto1115Ancient Books (IOI17_books)C++17
0 / 100
2099 ms469364 KiB
#include "books.h" #include "bits/stdc++.h" #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++) #define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--) #define pb push_back #define eb emplace_back #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vp = vector<P>; using vvp = vector<vp>; using vb = vector<bool>; using vvb = vector<vb>; using vs = vector<string>; const int inf = 1001001001; const ll linf = 1001001001001001001; template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll minimum_walk(vi p, int s) { int n = p.size(); map<vi, int> mp; vvi rev; vi ord(n); iota(all(ord), 0); int t = 0; do { mp[ord] = t++; rev.pb(ord); } while (next_permutation(all(ord))); vvi dp(24, vi(n, inf)); priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> q; dp[mp[p]][0] = 0; q.emplace(0, P(mp[p], 0)); while (!q.empty()) { auto[d, p] = q.top(); q.pop(); auto[bd, pos] = p; if (dp[bd][pos] < d) continue; rep(i, 4) { if (chmin(dp[bd][i], d + abs < int > (i - pos))) { q.emplace(dp[bd][i], P(bd, i)); } } iota(all(ord), 0); do { if (ord[0] != pos) continue; rep2(len, 2, n) { vi v(ord.begin(), ord.begin() + len); int nd = d; vi nb = rev[bd]; rep(i, len) { nd += abs(v[i] - v[(i + 1) % len]); nb[v[i]] = rev[bd][v[(i + 1) % len]]; } if (chmin(dp[mp[nb]][pos], nd)) { q.emplace(dp[mp[nb]][pos], P(mp[nb], pos)); } } } while (next_permutation(all(ord))); } return dp[0][0]; }
#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...