Submission #917705

#TimeUsernameProblemLanguageResultExecution timeMemory
917705LOLOLOTreatment Project (JOI20_treatment)C++17
0 / 100
3024 ms15956 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 3e5 + 10; const int lim = 1e7 + 10; int t[N], l[N], r[N]; int n, m; ll dp[N], c[N]; vector <int> ed[N]; ll run() { set <pair <ll, ll>> save; for (int i = 1; i <= m; i++) { if (l[i] == 1) { save.insert({c[i], i}); dp[i] = min(dp[i], c[i]); } } while (sz(save)) { auto t = *(save.begin()); save.erase(t); if (dp[t.s] < t.f) continue; for (auto x : ed[t.s]) { if (dp[x] > t.f + c[x]) { dp[x] = t.f + c[x]; save.insert({dp[x], x}); } } } ll ans = 1e16; for (int i = 1; i <= m; i++) { if (r[i] == n) ans = min(ans, dp[i]); } if (ans > 1e14) return -1; return ans; } ll solve() { mem(dp, 0x3f); cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> t[i] >> l[i] >> r[i] >> c[i]; } for (int i = 1; i <= m; i++) { for (int j = 1; j <= m; j++) { if (i == j) continue; if (t[i] <= t[j]) { int d = max(0, abs(t[i] - t[j]) - 1); int L = l[i] + d, R = r[i] - d; if (max(L, l[j]) - min(R, r[j]) <= 1) { ed[i].pb(j); ed[j].pb(i); //cout << " bruh\n"; } } } } return run(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { //solve(); cout << solve() << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...