답안 #901176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901176 2024-01-09T07:50:04 Z abcvuitunggio Sky Walking (IOI19_walk) C++17
24 / 100
4000 ms 888796 KB
#include "walk.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> q;
vector <int> a[100001],b[100001];
vector <pair <int, int>> ke[12000001],ve,nodes;
int n,m,d[12000001];
set <int> S;
void add(int i, int j){
    a[i].push_back(j);
    nodes.push_back({i,j});
}
int f(int i, int j){
    return lower_bound(nodes.begin(),nodes.end(),make_pair(i,j))-nodes.begin();
}
long long min_distance(vector<int32_t> x, vector<int32_t> h, vector<int32_t> l, vector<int32_t> r, vector<int32_t> y, int32_t s, int32_t g){
    n=x.size(),m=l.size();
    for (int i=0;i<n;i++)
        ve.push_back({-h[i],-i});
    for (int i=0;i<m;i++)
        ve.push_back({-y[i],i+1});
    sort(ve.begin(),ve.end());
    for (auto [i,j]:ve){
        i=-i,j=-j;
        if (j>=0){
            S.insert(j);
            continue;
        }
        j=-j-1;
        for (auto it=S.lower_bound(l[j]);it!=S.end()&&*it<=r[j];it++){
            add(*it,j);
            b[j].push_back(*it);
        }
    }
    add(s,-1);
    add(g,-1);
    sort(nodes.begin(),nodes.end());
    nodes.resize(unique(nodes.begin(),nodes.end())-nodes.begin());
    for (int i=0;i<n;i++)
        for (int j=0;j<(int)a[i].size()-1;j++){
            int u=f(i,a[i][j]),v=f(i,a[i][j+1]),w=abs((a[i][j]>=0?y[a[i][j]]:0)-(a[i][j+1]>=0?y[a[i][j+1]]:0));
            ke[u].push_back({v,w});
            ke[v].push_back({u,w});
        }
    for (int i=0;i<m;i++)
        for (int j=0;j<(int)b[i].size()-1;j++){
            int u=f(b[i][j],i),v=f(b[i][j+1],i),w=x[b[i][j+1]]-x[b[i][j]];
            ke[u].push_back({v,w});
            ke[v].push_back({u,w});
        }
    fill(d,d+nodes.size(),1e18);
    d[f(s,-1)]=0;
    q.push({0,f(s,-1)});
    while (!q.empty()){
        auto [du,u]=q.top();
        q.pop();
        if (du!=d[u])
            continue;
        for (auto [v,w]:ke[u])
            if (d[v]>d[u]+w){
                d[v]=d[u]+w;
                q.push({d[v],v});
            }
    }
    return (d[f(g,-1)]>1e17?-1:d[f(g,-1)]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 288336 KB Output is correct
2 Correct 62 ms 288296 KB Output is correct
3 Correct 60 ms 288336 KB Output is correct
4 Correct 62 ms 288208 KB Output is correct
5 Correct 62 ms 288340 KB Output is correct
6 Correct 62 ms 288308 KB Output is correct
7 Correct 63 ms 288340 KB Output is correct
8 Correct 63 ms 288340 KB Output is correct
9 Correct 60 ms 288340 KB Output is correct
10 Correct 67 ms 288340 KB Output is correct
11 Correct 61 ms 288336 KB Output is correct
12 Correct 63 ms 288600 KB Output is correct
13 Correct 62 ms 288336 KB Output is correct
14 Correct 61 ms 288340 KB Output is correct
15 Correct 61 ms 288324 KB Output is correct
16 Correct 61 ms 288352 KB Output is correct
17 Correct 66 ms 288360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 288188 KB Output is correct
2 Correct 62 ms 288324 KB Output is correct
3 Correct 1069 ms 391340 KB Output is correct
4 Correct 1089 ms 396652 KB Output is correct
5 Correct 767 ms 381360 KB Output is correct
6 Correct 695 ms 369280 KB Output is correct
7 Correct 751 ms 382640 KB Output is correct
8 Correct 1372 ms 422428 KB Output is correct
9 Correct 796 ms 385644 KB Output is correct
10 Correct 1409 ms 442720 KB Output is correct
11 Correct 554 ms 348440 KB Output is correct
12 Correct 385 ms 326120 KB Output is correct
13 Correct 1209 ms 426372 KB Output is correct
14 Correct 294 ms 325304 KB Output is correct
15 Correct 316 ms 327096 KB Output is correct
16 Correct 338 ms 328124 KB Output is correct
17 Correct 302 ms 327352 KB Output is correct
18 Correct 338 ms 334296 KB Output is correct
19 Correct 68 ms 289900 KB Output is correct
20 Correct 132 ms 307136 KB Output is correct
21 Correct 293 ms 326396 KB Output is correct
22 Correct 342 ms 326332 KB Output is correct
23 Correct 369 ms 334008 KB Output is correct
24 Correct 321 ms 325820 KB Output is correct
25 Correct 313 ms 326072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 307136 KB Output is correct
2 Execution timed out 4038 ms 888796 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 307136 KB Output is correct
2 Execution timed out 4038 ms 888796 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 288336 KB Output is correct
2 Correct 62 ms 288296 KB Output is correct
3 Correct 60 ms 288336 KB Output is correct
4 Correct 62 ms 288208 KB Output is correct
5 Correct 62 ms 288340 KB Output is correct
6 Correct 62 ms 288308 KB Output is correct
7 Correct 63 ms 288340 KB Output is correct
8 Correct 63 ms 288340 KB Output is correct
9 Correct 60 ms 288340 KB Output is correct
10 Correct 67 ms 288340 KB Output is correct
11 Correct 61 ms 288336 KB Output is correct
12 Correct 63 ms 288600 KB Output is correct
13 Correct 62 ms 288336 KB Output is correct
14 Correct 61 ms 288340 KB Output is correct
15 Correct 61 ms 288324 KB Output is correct
16 Correct 61 ms 288352 KB Output is correct
17 Correct 66 ms 288360 KB Output is correct
18 Correct 61 ms 288188 KB Output is correct
19 Correct 62 ms 288324 KB Output is correct
20 Correct 1069 ms 391340 KB Output is correct
21 Correct 1089 ms 396652 KB Output is correct
22 Correct 767 ms 381360 KB Output is correct
23 Correct 695 ms 369280 KB Output is correct
24 Correct 751 ms 382640 KB Output is correct
25 Correct 1372 ms 422428 KB Output is correct
26 Correct 796 ms 385644 KB Output is correct
27 Correct 1409 ms 442720 KB Output is correct
28 Correct 554 ms 348440 KB Output is correct
29 Correct 385 ms 326120 KB Output is correct
30 Correct 1209 ms 426372 KB Output is correct
31 Correct 294 ms 325304 KB Output is correct
32 Correct 316 ms 327096 KB Output is correct
33 Correct 338 ms 328124 KB Output is correct
34 Correct 302 ms 327352 KB Output is correct
35 Correct 338 ms 334296 KB Output is correct
36 Correct 68 ms 289900 KB Output is correct
37 Correct 132 ms 307136 KB Output is correct
38 Correct 293 ms 326396 KB Output is correct
39 Correct 342 ms 326332 KB Output is correct
40 Correct 369 ms 334008 KB Output is correct
41 Correct 321 ms 325820 KB Output is correct
42 Correct 313 ms 326072 KB Output is correct
43 Correct 167 ms 307136 KB Output is correct
44 Execution timed out 4038 ms 888796 KB Time limit exceeded
45 Halted 0 ms 0 KB -