Submission #405008

# Submission time Handle Problem Language Result Execution time Memory
405008 2021-05-15T14:13:43 Z Hazem Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
998 ms 225564 KB
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>

const int N = 3e4+10;
const int M = 3e2+10;
const LL INF = 1e9;
const LL LINF = 2e18;
const LL MOD = 1e9+7;   
const double PI = 3.141592653589793;

bool vis[N][N];
queue<pair<int,int>>que;
vector<int>vec[N];
int n,m,vis1[N],cnt;

int bfs(int st,int end){

    que.push({st-1,0});
    
    while(!que.empty()){
        
        int u = que.front().F%max(n,m)+1,dis = que.front().S;
        int p = que.front().F/max(n,m);

        if(u==end)
            return dis;

        que.pop();

        vec[u].push_back(p);

        int sz = vec[u].size();
        for(int i=vis1[u]?sz-1:0;i<sz;i++){
            int x = vec[u][i];
            if(u-x>=1)
                if(!vis[u-x][x])
                    que.push({u-x-1+x*max(n,m),dis+1}),vis[u-x][x] = 1,cnt++;
            
            if(u+x<=n)
                if(!vis[u+x][x])
                    que.push({u+x-1+x*max(n,m),dis+1}),vis[u+x][x] = 1,cnt++;
        }

        vec[u].pop_back();
        vis1[u] = 1;
    }

    return -1;
}

int main(){

    //freopen("out.txt","w",stdout);
    //freopen("doge_5_18.in","r",stdin);

    scanf("%d%d",&n,&m);
    int start,end;

    for(int i=1;i<=m;i++){
        int p,pos;
        scanf("%d%d",&pos,&p);
        pos++;
        vec[pos].push_back(p);

        if(i==1)start = pos;
        if(i==2)end = pos;
    }
    
    assert(start>=1&&start<=n&&end>=1&&end<=n);
    printf("%d\n",bfs(start,end));
    //printf("%d\n",cnt);
}   

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         scanf("%d%d",&pos,&p);
      |         ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:76:11: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
   76 |     printf("%d\n",bfs(start,end));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:76:11: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 968 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 3 ms 1356 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 5 ms 4172 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 8 ms 9164 KB Output is correct
21 Correct 2 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 6 ms 7304 KB Output is correct
24 Correct 8 ms 9228 KB Output is correct
25 Correct 3 ms 2636 KB Output is correct
26 Correct 6 ms 7884 KB Output is correct
27 Correct 7 ms 8516 KB Output is correct
28 Correct 9 ms 9616 KB Output is correct
29 Correct 10 ms 9164 KB Output is correct
30 Correct 7 ms 9192 KB Output is correct
31 Correct 8 ms 9280 KB Output is correct
32 Correct 10 ms 9252 KB Output is correct
33 Correct 13 ms 9304 KB Output is correct
34 Correct 10 ms 9164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 2 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 3 ms 1224 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 2 ms 972 KB Output is correct
17 Correct 4 ms 4172 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 7 ms 9140 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 6 ms 7348 KB Output is correct
24 Correct 9 ms 9164 KB Output is correct
25 Correct 3 ms 2636 KB Output is correct
26 Correct 7 ms 7884 KB Output is correct
27 Correct 7 ms 8524 KB Output is correct
28 Correct 11 ms 9676 KB Output is correct
29 Correct 11 ms 9248 KB Output is correct
30 Correct 8 ms 9164 KB Output is correct
31 Correct 8 ms 9224 KB Output is correct
32 Correct 8 ms 9280 KB Output is correct
33 Correct 13 ms 9292 KB Output is correct
34 Correct 10 ms 9156 KB Output is correct
35 Correct 14 ms 8492 KB Output is correct
36 Correct 4 ms 2892 KB Output is correct
37 Correct 13 ms 10532 KB Output is correct
38 Correct 18 ms 12080 KB Output is correct
39 Correct 9 ms 1740 KB Output is correct
40 Correct 11 ms 4044 KB Output is correct
41 Correct 16 ms 9664 KB Output is correct
42 Correct 14 ms 8012 KB Output is correct
43 Correct 12 ms 8652 KB Output is correct
44 Correct 12 ms 9292 KB Output is correct
45 Correct 38 ms 10200 KB Output is correct
46 Correct 26 ms 9968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 2 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 4 ms 4172 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 7 ms 9088 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 6 ms 7372 KB Output is correct
24 Correct 8 ms 9164 KB Output is correct
25 Correct 3 ms 2608 KB Output is correct
26 Correct 6 ms 7884 KB Output is correct
27 Correct 7 ms 8524 KB Output is correct
28 Correct 9 ms 9676 KB Output is correct
29 Correct 10 ms 9244 KB Output is correct
30 Correct 8 ms 9164 KB Output is correct
31 Correct 9 ms 9284 KB Output is correct
32 Correct 8 ms 9292 KB Output is correct
33 Correct 13 ms 9292 KB Output is correct
34 Correct 10 ms 9164 KB Output is correct
35 Correct 13 ms 8524 KB Output is correct
36 Correct 3 ms 2892 KB Output is correct
37 Correct 13 ms 10560 KB Output is correct
38 Correct 17 ms 12004 KB Output is correct
39 Correct 9 ms 1740 KB Output is correct
40 Correct 11 ms 4140 KB Output is correct
41 Correct 16 ms 9676 KB Output is correct
42 Correct 14 ms 8012 KB Output is correct
43 Correct 12 ms 8680 KB Output is correct
44 Correct 12 ms 9276 KB Output is correct
45 Correct 37 ms 10220 KB Output is correct
46 Correct 26 ms 10060 KB Output is correct
47 Correct 31 ms 35712 KB Output is correct
48 Correct 8 ms 1496 KB Output is correct
49 Correct 8 ms 1484 KB Output is correct
50 Correct 6 ms 1356 KB Output is correct
51 Correct 120 ms 149420 KB Output is correct
52 Correct 147 ms 185076 KB Output is correct
53 Correct 23 ms 20932 KB Output is correct
54 Correct 40 ms 63236 KB Output is correct
55 Correct 54 ms 83340 KB Output is correct
56 Correct 89 ms 123700 KB Output is correct
57 Correct 3 ms 2764 KB Output is correct
58 Correct 95 ms 124040 KB Output is correct
59 Correct 93 ms 114688 KB Output is correct
60 Correct 89 ms 114632 KB Output is correct
61 Correct 87 ms 111348 KB Output is correct
62 Correct 238 ms 225564 KB Output is correct
63 Correct 484 ms 141500 KB Output is correct
64 Correct 498 ms 135668 KB Output is correct
65 Correct 612 ms 133688 KB Output is correct
66 Correct 998 ms 131528 KB Output is correct
67 Correct 487 ms 127928 KB Output is correct