Submission #315939

#TimeUsernameProblemLanguageResultExecution timeMemory
315939MarcoMeijerTreatment Project (JOI20_treatment)C++14
0 / 100
3078 ms18508 KiB
#include <bits/stdc++.h> using namespace std; // macros typedef __int128 ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define INF 1e18 #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // input template<class T> void IN(T& x) {cin >> x;} template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); } // output template<class T1, class T2> void OUT(const pair<T1,T2>& x); template<class T> void OUT(const vector<T>& x); template<class T> void OUT(const T& x) {cout << x;} template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); } template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);} template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);} template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); } template<class H> void OUTLS(const H& h) {OUTL(h); } template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); } //===================// // Added libraries // //===================// //===================// //end added libraries// //===================// void program(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); program(); } //===================// // begin program // //===================// const int MX = 5e5; #define X real() #define Y imag() typedef complex<ll> Vec; struct LineSeg { // line seg from a -> b Vec a, b; }; ll cross(Vec a, Vec b) {return a.X*b.Y - a.Y*b.X;} bool collide(LineSeg a, LineSeg b) { if((cross(a.b - a.a, b.a - a.a) <= 0) != (cross(a.b - a.a, b.b - a.a) > 0) && (cross(a.a - a.b, b.a - a.b) <= 0) != (cross(a.a - a.b, b.b - a.b) > 0)) return 0; if((cross(b.b - b.a, a.a - b.a) <= 0) != (cross(b.b - b.a, a.b - b.a) > 0) && (cross(b.a - b.b, a.a - b.b) <= 0) != (cross(b.a - b.b, a.b - b.b) > 0)) return 0; return 1; } int n, m; long long T[MX], L[MX], R[MX], C[MX]; vi adj[MX]; ll dist[MX]; bool isConnected(int i, int j) { Vec a1 = {T[i],L[i]}; Vec a2 = {T[i],R[i]}; Vec a3 = {T[i]+(R[i]-L[i])/2, (L[i]+R[i])/2}; Vec b1 = {T[j],L[j]}; Vec b2 = {T[j],R[j]}; Vec b3 = {T[j]+(R[j]-L[j])/2, (L[j]+R[j])/2}; LineSeg A1 = {a1,a3}, A2 = {a2, a3}; LineSeg B1 = {b1,b3}, B2 = {b2, b3}; if(collide(A1, B1)) return 1; if(collide(A1, B2)) return 1; if(collide(A2, B1)) return 1; if(collide(A2, B2)) return 1; return 0; } void program() { IN(n,m); RE(i,m) IN(T[i], L[i], R[i], C[i]); RE(i,m) { T[i]*=2; if(L[i] == 1) L[i] = -INF; else L[i] *= 2; if(R[i] == n) R[i] = INF; else R[i] = (R[i]+1)*2; } n*=2; RE(i,m) RE(j,m) { if(i == j) continue; if(isConnected(i,j)) adj[i].pb(j); } priority_queue<lll,vlll,greater<lll>> pq; RE(i,m) dist[i] = INF; RE(i,m) if(L[i] == -INF) { dist[i] = 0; pq.push({0,i}); } while(!pq.empty()) { lll p = pq.top(); pq.pop(); if(dist[p.se] != p.fi) continue; FOR(v,adj[p.se]) { if(dist[v] > p.fi+C[p.se]) { dist[v] = p.fi+C[p.se]; pq.push({dist[v], v}); } } } ll ans = INF; RE(i,m) if(R[i] == INF) { ans = min(ans, dist[i]+C[i]); } if(ans == INF) ans = -1; OUTL((long long)ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...