# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
410282 | 2021-05-22T12:19:36 Z | mat_v | Robot (JOI21_ho_t4) | C++14 | 292 ms | 34728 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<ll,int> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); struct edge{ int x; int boja; ll v; }; ll maks = 1e9; struct node{ int cale; int x; ll v; }; bool operator < (const node &a, const node &b){ return a.v < b.v; } bool operator > (const node &a, const node &b){ return a.v > b.v; } int n,m; vector<edge> graf[100005]; vector<pii> pravi[100005]; ll dist[100005]; bool cmp(edge a, edge b){ if(a.boja < b.boja)return 1; return 0; } map<pii,bool>post; int main() { ios_base::sync_with_stdio(false); cin.tie(0); maks *= maks; cin >> n >> m; // n = 1005; // m = 2005; ff(i,1,m){ int a,b,c,d; // a = rnd()%n; // b = rnd()%n; // a++; // b++; // c = rnd()%m; // c++; // d = rnd()%1000000; // if(post[{a,b}]){ // a = (rnd()%n) + 1; // b = (rnd()%n) + 1; // } // post[{a,b}] = post[{b,a}] = 1; cin >> a >> b >> c >> d; graf[a].pb({b,c,d}); graf[b].pb({a,c,d}); } ff(i,1,n)sort(graf[i].begin(), graf[i].end(), cmp); ff(r,1,n){ int len = graf[r].size(); if(len == 0)continue; int last = 0; ll sum = 0; int koji = r; ff(i,0,len - 1){ if(graf[koji][i].boja != graf[koji][last].boja){ ff(j,last,i-1){ if(j < i-1){ int p1 = graf[koji][j].x; int p2 = graf[koji][i - 1].x; ll duz = sum - graf[koji][i - 1].v; pravi[p1].pb({duz,p2}); if(i-1 != last){ int p1 = graf[koji][j].x; int p2 = graf[koji][i - 2].x; ll duz = sum - graf[koji][i - 2].v; pravi[p1].pb({duz,p2}); } } else{ if(last != i-1){ int p1 = graf[koji][i - 1].x; int p2 = graf[koji][i - 2].x; ll duz = sum - graf[koji][i - 2].v; pravi[p1].pb({duz,p2}); } } ll duz1 = graf[koji][j].v; int gde = graf[koji][j].x; duz1 = min(duz1, sum - graf[koji][j].v); pravi[koji].pb({duz1,gde}); } last = i; sum = graf[koji][i].v; } else{ sum += graf[koji][i].v; } } ff(j,last,len-1){ if(j < len-1){ int p1 = graf[koji][j].x; int p2 = graf[koji][len - 1].x; ll duz = sum - graf[koji][len - 1].v; pravi[p1].pb({duz,p2}); } else{ if(last != len-1){ int p1 = graf[koji][len - 1].x; int p2 = graf[koji][len - 2].x; ll duz = sum - graf[koji][len - 2].v; pravi[p1].pb({duz,p2}); } } ll duz1 = graf[koji][j].v; int gde = graf[koji][j].x; duz1 = min(duz1, sum - graf[koji][j].v); pravi[koji].pb({duz1,gde}); } } priority_queue<pii> pq; dist[1] = 0; ff(i,2,n)dist[i] = maks; pq.push({0,1}); while(!pq.empty()){ pii sta = pq.top(); pq.pop(); for(auto c:pravi[sta.yy]){ int koji = c.yy; if(dist[koji] > c.xx - sta.xx){ dist[koji] = c.xx - sta.xx; pq.push({-dist[koji],koji}); } } } if(dist[n] < maks)cout << dist[n] << "\n"; else cout << -1 << "\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 3 ms | 4940 KB | Output is correct |
4 | Correct | 3 ms | 4940 KB | Output is correct |
5 | Correct | 4 ms | 4940 KB | Output is correct |
6 | Correct | 3 ms | 4940 KB | Output is correct |
7 | Correct | 4 ms | 5068 KB | Output is correct |
8 | Correct | 4 ms | 5068 KB | Output is correct |
9 | Correct | 5 ms | 5296 KB | Output is correct |
10 | Correct | 5 ms | 5324 KB | Output is correct |
11 | Correct | 5 ms | 5196 KB | Output is correct |
12 | Incorrect | 5 ms | 5196 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 84 ms | 18496 KB | Output is correct |
2 | Correct | 38 ms | 10712 KB | Output is correct |
3 | Correct | 130 ms | 29404 KB | Output is correct |
4 | Correct | 60 ms | 13888 KB | Output is correct |
5 | Correct | 221 ms | 30980 KB | Output is correct |
6 | Correct | 227 ms | 34456 KB | Output is correct |
7 | Correct | 218 ms | 33180 KB | Output is correct |
8 | Correct | 289 ms | 34520 KB | Output is correct |
9 | Correct | 292 ms | 34728 KB | Output is correct |
10 | Correct | 165 ms | 24400 KB | Output is correct |
11 | Correct | 111 ms | 19020 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 3 ms | 4940 KB | Output is correct |
4 | Correct | 3 ms | 4940 KB | Output is correct |
5 | Correct | 4 ms | 4940 KB | Output is correct |
6 | Correct | 3 ms | 4940 KB | Output is correct |
7 | Correct | 4 ms | 5068 KB | Output is correct |
8 | Correct | 4 ms | 5068 KB | Output is correct |
9 | Correct | 5 ms | 5296 KB | Output is correct |
10 | Correct | 5 ms | 5324 KB | Output is correct |
11 | Correct | 5 ms | 5196 KB | Output is correct |
12 | Incorrect | 5 ms | 5196 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |