제출 #516000

#제출 시각아이디문제언어결과실행 시간메모리
516000Jeff12345121Pinball (JOI14_pinball)C++14
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> #define in cin #define out cout using namespace std; //ifstream in("in.in"); //ofstream out("out.out"); int n, m; const int inf = 1000000005; struct Dev { int l, r, hole, cost; }; vector<Dev> dev; template<typename F> int getDp(int len, Dev goal, F f) { /// we want to have all the pinballs take it past left // dp[i] = minCost to get all balls to this device vector<int> dp(len + 1); for (int i = 1; i <= len; i++) { dp[i] = inf; } int ans = inf; for (int i = 1; i <= len; i++) { if (f(dev[i])) { dp[i] = dev[i].cost; } for (int j = 1; j < i; j++) { if (dev[i].l <= dev[j].hole && dev[j].hole <= dev[i].r) { dp[i] = min(dp[i], dp[j] + dev[i].cost); } } if (goal.l <= dev[i].hole && dev[i].hole <= goal.r) { ans = min(ans, dp[i]); } } return ans; } int main() { in >> m >> n; /// m is number of lines, n is number of collumns dev.resize(m + 1); for (int i = 1; i <= m; i++) { int l, r, hole, cost; in >> l >> r >> hole >> cost; dev[i] = {l, r, hole, cost}; } int ans = inf; for (int i = 1; i <= m; i++) { /// i is middle int leftCost = getDp(i - 1, dev[i], [&](Dev x) { return x.l == 1; }); int rightCost = getDp(i - 1, dev[i], [&](Dev x) { return x.r == n; }); ans = min(ans, leftCost + rightCost + dev[i].cost); // cout << "\n"; } if (ans == inf) { out << "-1\n"; } else { out << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...