Submission #315949

#TimeUsernameProblemLanguageResultExecution timeMemory
315949MarcoMeijerTreatment Project (JOI20_treatment)C++14
0 / 100
3037 ms15608 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 onSegment(Vec p, Vec q, Vec r) { if (q.X <= max(p.X, r.X) && q.X >= min(p.X, r.X) && q.Y <= max(p.Y, r.Y) && q.Y >= min(p.Y, r.Y)) return 1; return 0; } ll orientation(Vec p, Vec q, Vec r) { ll val = (q.Y - p.Y) * (r.X - q.X) - (q.X - p.X) * (r.Y - q.Y); if (val == 0) return 0; return (val > 0) ? 1 : 2; } bool collide(LineSeg a, LineSeg b) { Vec p1 = a.a; Vec q1 = a.b; Vec p2 = b.a; Vec q2 = b.b; ll o1 = orientation(p1, q1, p2); ll o2 = orientation(p1, q1, q2); ll o3 = orientation(p2, q2, p1); ll o4 = orientation(p2, q2, q1); if (o1 != o2 && o3 != o4) return 1; if (o1 == 0 && onSegment(p1, p2, q1)) return 1; if (o2 == 0 && onSegment(p1, q2, q1)) return 1; if (o3 == 0 && onSegment(p2, p1, q2)) return 1; if (o4 == 0 && onSegment(p2, q1, q2)) return 1; return 0; } 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(a1 == b1 || a1 == b2 || a1 == b3 || a2 == b1 || a2 == b2 || a2 == b3 || a3 == b1 || a3 == b2 || a3 == b3) return 1; 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...