제출 #789876

#제출 시각아이디문제언어결과실행 시간메모리
789876pravcoderRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
308 ms524288 KiB
#include "railroad.h" #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> v2ll; typedef vector<int> vi; typedef pair<int, int> pi; typedef vector<pi> vpi; ll plan_roller_coaster(vi s, vi t) { int n = (int) s.size(); vll empty(n, 1e12); v2ll costs(n, empty); for (int i = 0; i < n-1; i++) { for (int j = i+1; j < n; j++) { costs[i][j] = (t[i] - s[j]) * (t[i] > s[j]); costs[j][i] = (t[j] - s[i]) * (t[j] > s[i]); } } v2ll d(1<<n, empty); for (int i = 0; i < n; i++) { d[1<<i][i] = 0; } ll ans = 1e12; for (int b = 1; b < (1<<n); b++) { for (int c = 0; c < n; c++) { if (b == (1 << n) - 1) { ans = min(ans, d[b][c]); } else { if ((b & (1 << c)) > 0) { for (int i = 0; i < n; i++) { if ((b & (1 << i)) == 0) { d[b | (1 << i)][i] = min(d[b | (1 << i)][i], d[b][c] + costs[c][i]); } } } } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...