Submission #508722

#TimeUsernameProblemLanguageResultExecution timeMemory
508722Jeff12345121Pinball (JOI14_pinball)C++14
11 / 100
1085 ms94188 KiB
#include <bits/stdc++.h> #define in cin #define out cout #define int long long using namespace std; //ifstream in("in.in"); //ofstream out("out.out"); struct device { int l, r, hole, cost; }; vector<device> devices; const int nmax = 20, mmax = 1005, inf = (1LL << 60); int n, m, dp[nmax][mmax][mmax]; void minSelf(int &a, int b) { if (b < a) { a = b; } } int ans = inf; void check(int mask) { set<int> s; for (int i = 1; i <= m; i++) { s.insert(i); } int cost = 0; for (int i = 0; i < n; i++) { set<int> s2; if (mask & (1 << i)) cost += devices[i + 1].cost; for (auto k : s) { if ( (mask & (1 << i)) && (devices[i + 1].l <= k && k <= devices[i + 1].r) ) { s2.insert(devices[i + 1].hole); } else { s2.insert(k); } } s = s2; } if (s.size() == 1) { ans = min(ans, cost); } } int32_t main() { in >> n >> m; if (m == 1) { out << "0\n"; return 0; } devices.resize(n + 1); for (int i = 1; i <= n; i++) { int l, r, hole, cost; in >> l >> r >> hole >> cost; devices[i] = {l, r, hole, cost}; } for (int mask = 0; mask < (1 << n); mask++) { check(mask); } 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...