Submission #581415

#TimeUsernameProblemLanguageResultExecution timeMemory
581415VanillaPinball (JOI14_pinball)C++17
51 / 100
1082 ms2260 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int64; const int maxn = 1e5 + 2; int64 a[maxn], b[maxn], c[maxn], cost[maxn]; int64 l[maxn], r[maxn]; // l[i] -> min cost sa ajungi in device i incepand de pe coloana 1 // r[i] -> min cost sa ajungi in device i incepand de pe coloana m int main() { int n,m; cin >> n >> m; for (int i = 0; i < n; i++){ cin >> a[i] >> b[i] >> c[i] >> cost[i]; l[i] = r[i] = 1e18; } int64 rs = 1e18; for (int i = 0; i < n; i++){ if (a[i] == 1) l[i] = cost[i]; if (b[i] == m) r[i] = cost[i]; for (int j = i - 1; j >= 0; j--){ if (a[i] <= c[j] && c[j] <= b[i]) l[i] = min(l[i], l[j] + cost[i]); if (a[i] <= c[j] && c[j] <= b[i]) r[i] = min(r[i], r[j] + cost[i]); } rs = min(rs, l[i] + r[i] - cost[i]); } cout << (rs == 1e18 ? -1: rs); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...