답안 #405853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405853 2021-05-17T00:27:02 Z A_D Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
75 ms 70504 KB
#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
using namespace std;
const int N=2e3+100;
vector<int> vec[N];
int vis[N][N];
int dis,st,n;
set<int> stt;
deque<ii> deq;
bool in(int x)
{
    return 0<=x && x<n;
}
void fix(int v,int w)
{
    if(in(v+w)&&vis[v+w][w]>vis[v][w]+1){
//        cout<<5<<endl;
        vis[v+w][w]=vis[v][w]+1;
        deq.push_back({v+w,w});
    }
    if(in(v-w)&&vis[v-w][w]>vis[v][w]+1){
//        cout<<5<<endl;
        vis[v-w][w]=vis[v][w]+1;
        deq.push_back({v-w,w});
    }
}
int bfs()
{
    deq.push_back({st,0});
    while(deq.empty()==0){
        int v=deq[0].F;
        int w=deq[0].S;
        deq.pop_front();
        stt.insert(v);
        if(v==dis)return vis[v][w];
        fix(v,w);
//        cout<<v<<" "<<w<<endl;
        for(auto x:vec[v]){
            vis[v][x]=min(vis[v][x],vis[v][w]);
            fix(v,x);
//            cout<<v<<" "<<x<<endl;
        }
        vec[v].clear();
    }
    return -1;
}
main()
{
    int m;
    cin>>n>>m;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            vis[i][j]=1e18;
        }
    }
    int x,y;
    cin>>x>>y;
    vis[x][0]=0;
    vec[x].push_back(y);
    st=x;
    cin>>x>>y;
    vec[x].push_back(y);
    dis=x;
    m-=2;
    while(m--){
        cin>>x>>y;
        vec[x].push_back(y);
    }
    cout<<bfs()<<endl;
//    for(auto x:stt)cout<<x<<" ";cout<<endl;
}
/*
5 3
0 2
1 1
4 1
*/

Compilation message

skyscraper.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 284 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 736 KB Output is correct
11 Correct 2 ms 844 KB Output is correct
12 Correct 2 ms 844 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 844 KB Output is correct
15 Correct 2 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 2 ms 844 KB Output is correct
12 Correct 2 ms 844 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 844 KB Output is correct
15 Correct 2 ms 868 KB Output is correct
16 Correct 2 ms 1484 KB Output is correct
17 Correct 6 ms 7628 KB Output is correct
18 Correct 14 ms 29100 KB Output is correct
19 Correct 16 ms 33208 KB Output is correct
20 Correct 17 ms 33356 KB Output is correct
21 Correct 3 ms 3180 KB Output is correct
22 Correct 14 ms 29644 KB Output is correct
23 Correct 13 ms 26728 KB Output is correct
24 Correct 17 ms 31692 KB Output is correct
25 Correct 18 ms 33280 KB Output is correct
26 Correct 18 ms 33268 KB Output is correct
27 Correct 17 ms 33288 KB Output is correct
28 Correct 19 ms 33344 KB Output is correct
29 Correct 22 ms 33356 KB Output is correct
30 Correct 17 ms 33252 KB Output is correct
31 Correct 19 ms 33348 KB Output is correct
32 Correct 18 ms 33364 KB Output is correct
33 Correct 30 ms 33300 KB Output is correct
34 Correct 26 ms 33388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 476 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 2 ms 844 KB Output is correct
12 Correct 2 ms 844 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 872 KB Output is correct
15 Correct 2 ms 872 KB Output is correct
16 Correct 2 ms 1376 KB Output is correct
17 Correct 5 ms 7628 KB Output is correct
18 Correct 14 ms 29052 KB Output is correct
19 Correct 16 ms 33228 KB Output is correct
20 Correct 17 ms 33356 KB Output is correct
21 Correct 3 ms 3148 KB Output is correct
22 Correct 14 ms 29644 KB Output is correct
23 Correct 14 ms 26684 KB Output is correct
24 Correct 17 ms 31692 KB Output is correct
25 Correct 17 ms 33224 KB Output is correct
26 Correct 17 ms 33248 KB Output is correct
27 Correct 18 ms 33292 KB Output is correct
28 Correct 20 ms 33308 KB Output is correct
29 Correct 22 ms 33324 KB Output is correct
30 Correct 17 ms 33356 KB Output is correct
31 Correct 19 ms 33356 KB Output is correct
32 Correct 20 ms 33312 KB Output is correct
33 Correct 28 ms 33356 KB Output is correct
34 Correct 23 ms 33316 KB Output is correct
35 Correct 29 ms 24672 KB Output is correct
36 Correct 11 ms 14972 KB Output is correct
37 Correct 27 ms 32836 KB Output is correct
38 Correct 35 ms 34192 KB Output is correct
39 Correct 33 ms 33820 KB Output is correct
40 Correct 32 ms 33924 KB Output is correct
41 Correct 35 ms 33976 KB Output is correct
42 Correct 29 ms 33740 KB Output is correct
43 Correct 33 ms 33848 KB Output is correct
44 Correct 30 ms 33740 KB Output is correct
45 Correct 74 ms 34320 KB Output is correct
46 Correct 50 ms 34300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 2 ms 844 KB Output is correct
12 Correct 2 ms 844 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 844 KB Output is correct
15 Correct 2 ms 844 KB Output is correct
16 Correct 2 ms 1484 KB Output is correct
17 Correct 5 ms 7628 KB Output is correct
18 Correct 15 ms 29064 KB Output is correct
19 Correct 16 ms 33228 KB Output is correct
20 Correct 18 ms 33384 KB Output is correct
21 Correct 3 ms 3148 KB Output is correct
22 Correct 14 ms 29644 KB Output is correct
23 Correct 13 ms 26744 KB Output is correct
24 Correct 17 ms 31692 KB Output is correct
25 Correct 17 ms 33256 KB Output is correct
26 Correct 17 ms 33260 KB Output is correct
27 Correct 17 ms 33352 KB Output is correct
28 Correct 19 ms 33376 KB Output is correct
29 Correct 21 ms 33356 KB Output is correct
30 Correct 19 ms 33228 KB Output is correct
31 Correct 19 ms 33356 KB Output is correct
32 Correct 18 ms 33236 KB Output is correct
33 Correct 28 ms 33336 KB Output is correct
34 Correct 26 ms 33292 KB Output is correct
35 Correct 30 ms 24644 KB Output is correct
36 Correct 10 ms 14924 KB Output is correct
37 Correct 27 ms 32908 KB Output is correct
38 Correct 35 ms 34232 KB Output is correct
39 Correct 32 ms 33844 KB Output is correct
40 Correct 32 ms 33940 KB Output is correct
41 Correct 38 ms 33996 KB Output is correct
42 Correct 30 ms 33748 KB Output is correct
43 Correct 29 ms 33800 KB Output is correct
44 Correct 32 ms 33768 KB Output is correct
45 Correct 75 ms 34376 KB Output is correct
46 Correct 52 ms 34316 KB Output is correct
47 Runtime error 63 ms 70504 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -