제출 #789909

#제출 시각아이디문제언어결과실행 시간메모리
789909Minindu206Roller Coaster Railroad (IOI16_railroad)C++14
64 / 100
78 ms13728 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { #define int long long int n = (int)s.size(); if (n > 16) { vector<pair<int, int>> ss, tt; for (int i = 0; i < n; i++) { tt.push_back({t[i], i}); ss.push_back({s[i], i}); } sort(ss.rbegin(), ss.rend()); sort(tt.rbegin(), tt.rend()); int i = 0, j = 1; while (j < n) { if (ss[i].second != tt[j].second) { if (tt[j].first > ss[i].first) return 999; } else if (i != n - 1) { if (tt[j].first > ss[i + 1].first) return 999; } i++, j++; } return 0; } vector<vector<int>> dp((1 << n), vector<int>(n, LLONG_MAX)); for (int i = 0; i < n; i++) dp[(1 << i)][i] = 0; for (int i = 0; i < (1 << n); i++) { for (int j = 0; j < n; j++) { if (!((1 << j) & (i))) for (int k = 0; k < n; k++) { if (((1 << k) & i)) { int dis = max((int)(t[k] - s[j]), 0LL); dp[i | (1 << j)][j] = min(dp[i][k] + dis, dp[i | (1 << j)][j]); } } } } int ans = LLONG_MAX; for (int i = 0; i < n; i++) { ans = min(ans, dp[(1 << n) - 1][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...