Submission #1030873

# Submission time Handle Problem Language Result Execution time Memory
1030873 2024-07-22T11:08:26 Z irmuun Sky Walking (IOI19_walk) C++17
10 / 100
491 ms 1048576 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

ll min_distance(vector<int>x,vector<int>h,vector<int>l,vector<int>r,vector<int>y,int s,int g){
    int n=x.size(),m=l.size();
    vector<int>Y=y;
    sort(all(Y));
    vector<int>d;
    d.pb(0);
    for(int i=0;i<Y.size();i++){
        if(i==0||Y[i]!=Y[i-1]){
            d.pb(Y[i]);
        }
    }
    vector<int>y_ind(y.size());
    for(int i=0;i<m;i++){
        y_ind[i]=lower_bound(all(d),y[i])-d.begin();
    }
    vector<pair<int,int>>adj[n][m+1];
    ll dist[n][m+1];
    if(n<=50&&m<=50){
        for(int i=0;i<n;i++){
            for(int j=0;j<=m;j++){
                dist[i][j]=1e18;
            }
        }
        for(int j=0;j<m;j++){
            int last=-1;
            for(int i=l[j];i<=r[j];i++){
                if(h[i]>=y[j]){
                    if(last>-1){
                        adj[last][y_ind[j]].pb({i,y_ind[j]});
                        adj[i][y_ind[j]].pb({last,y_ind[j]});
                    }
                    last=i;
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=1;j<d.size();j++){
                if(d[j]<=h[i]){
                    adj[i][j-1].pb({i,j});
                    adj[i][j].pb({i,j-1});
                }
            }
        }
    }
    set<tuple<ll,int,int>>st;
    st.insert({0,s,0});
    dist[s][0]=0;
    while(!st.empty()){
        auto [cur,ni,nj]=*st.begin();
        st.erase(st.begin());
        if(dist[ni][nj]!=cur) continue;
        for(auto [nx,ny]:adj[ni][nj]){
            ll new_cur=cur+abs(x[ni]-x[nx])+abs(d[nj]-d[ny]);
            if(new_cur<dist[nx][ny]){
                dist[nx][ny]=new_cur;
                st.insert({new_cur,nx,ny});
            }
        }
    }
    if(dist[g][0]==1e18) dist[g][0]=-1;
    return dist[g][0];
}

Compilation message

walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<Y.size();i++){
      |                 ~^~~~~~~~~
walk.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             for(int j=1;j<d.size();j++){
      |                         ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 432 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 491 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 473 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 473 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 432 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Runtime error 491 ms 1048576 KB Execution killed with signal 9
21 Halted 0 ms 0 KB -