# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
410285 | mat_v | Robot (JOI21_ho_t4) | C++14 | 341 ms | 43736 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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){
if(i == len || 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;
}
}
}
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |