Submission #682748

#TimeUsernameProblemLanguageResultExecution timeMemory
682748EvirirTreatment Project (JOI20_treatment)C++17
0 / 100
3040 ms7424 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #define watch(x) cout<<(#x)<<"="<<(x)<<'\n' #define mset(d,val) memset(d,val,sizeof(d)) #define cbug if(DEBUG) cout #define setp(x) cout<<fixed<<setprecision(x) #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define forn(i,a,b) for(int i=(a);i<(b);i++) #define fore(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define F first #define S second #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; //template<typename T> //using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void SD(int t=0){ cout<<"PASSED "<<t<<endl; } ostream& operator<<(ostream &out, ii x){ out<<"("<<x.F<<","<<x.S<<")"; return out; } template<typename T> void amax(T &a, T b){ a=max(a,b); } template<typename T> void amin(T &a, T b){ a=min(a,b); } const ll INF = ll(1e18); const int MOD = 998244353; enum class OpType { kInsert, kRemove }; class PointSegmentTree{ private: int size_; vector<unordered_set<int>> v; void update(int p, ll val, OpType type, int k, int l, int r) { if(p < l || r < p) return; if(l == r){ if (type == OpType::kInsert) v[k].insert(val); else v[k].erase(val); return; } int mid = (l+r)>>1; update(p, val, type, k*2, l, mid); update(p, val, type, k*2+1, mid+1, r); v[k] = merge(v[k*2], v[k*2+1]); } unordered_set<int> query(int s, int e, int k, int l, int r) { if(e < l || r < s) return {}; //dummy value if(s <= l && r <= e) return v[k]; int mid = (l+r)>>1; unordered_set<int> lc = query(s, e, k*2, l, mid); unordered_set<int> rc = query(s, e, k*2+1, mid+1, r); return merge(lc, rc); } public: PointSegmentTree(): v(vector<unordered_set<int>>()) {} PointSegmentTree(int n){ for(size_=1;size_<n;) size_<<=1; v.resize(size_*4); } //void reset(){} inline unordered_set<int> merge(const unordered_set<int> &x, const unordered_set<int> &y){ unordered_set<int> res(x.begin(), x.end()); res.insert(y.begin(), y.end()); return res; } inline void update(int p, ll val, OpType type){ update(p, val, type, 1, 0, size_-1); } inline unordered_set<int> query(int l, int r){ return query(l, r, 1, 0, size_-1); } }; const bool DEBUG = 0; const int MAXN = 100005; const int LG = 21; struct Project { ll t, l, r, cost; }; istream& operator>>(istream& in, Project &p) { in >> p.t >> p.l >> p.r >> p.cost; p.l--; p.r--; return in; } bool isConnected(Project p1, Project p2) { if (p1.t > p2.t) swap(p1, p2); return p2.l + p2.t <= p1.r + p1.t + 1 && p2.r - p2.t >= p1.l - p1.t - 1; } ll n; int m; vector<Project> projects; ll dist[MAXN]; void dijkstra() { priority_queue<ii, vector<ii>, greater<ii>> q; // (distance, node) fill(dist, dist + m, INF); for (int i = 0; i < m; i++) { auto p = projects[i]; if (p.l != 0) continue; dist[i] = p.cost; q.push({dist[i], i}); } while (!q.empty()) { auto [cur_dist, u] = q.top(); q.pop(); if (cur_dist > dist[u]) continue; for (int i = 0; i < m; i++) { if (dist[i] <= cur_dist + projects[i].cost) continue; if (!isConnected(projects[u], projects[i])) continue; dist[i] = cur_dist + projects[i].cost; q.push({dist[i], i}); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; projects.resize(m); forn(i, 0, m) cin >> projects[i]; dijkstra(); ll ans = INF; forn(i,0,m) { if (projects[i].r == n - 1) { ans = min(ans, dist[i]); } } if (ans == INF) ans = -1; cout << ans << '\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...