Submission #48305

# Submission time Handle Problem Language Result Execution time Memory
48305 2018-05-11T15:47:41 Z Unit Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 71952 KB
#include<bits/stdc++.h>
#include<unordered_set>
using namespace std;
 
#define se second
#define fi first
#define mk(a,b) make_pair(a,b)
 
typedef pair<int,int> pii;
typedef pair<int,pii> pipii;
 
int N,M;
vector<int> V[30010];
bool vis[30010];
int s,t;
unordered_set<int> st[30010];
 
int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i < M; i++)
    {
        int b,p;
        scanf("%d%d",&b,&p);
        V[b].push_back(p);
        if(i == 0)s = b;
        if(i == 1)t = b;
    }
 
    queue<pipii> que;
    que.push(mk(1,mk(s,0)));
    while(que.size())
    {
        pipii now = que.front();
        que.pop();
        if(st[now.se.fi].count(now.se.se) != 0)continue;
        st[now.se.fi].insert(now.se.se);
        if(now.se.fi == t)
        {
            printf("%d\n",now.fi - 1);
            return 0;
        }
        if(!vis[now.se.fi])
        {
            vis[now.se.fi] = true;
            for(int i = 0; i < V[now.se.fi].size(); i++)
            {
                if(now.se.fi + V[now.se.fi][i] < N)
                    que.push(mk(now.fi + 1,mk(now.se.fi + V[now.se.fi][i],V[now.se.fi][i])));
                if(0 <= now.se.fi - V[now.se.fi][i])
                    que.push(mk(now.fi + 1,mk(now.se.fi - V[now.se.fi][i],V[now.se.fi][i])));
            }
        }
        vis[now.se.fi] = true;
        if(now.se.fi + now.se.se < N)que.push(mk(now.fi + 1,mk(now.se.fi + now.se.se,now.se.se)));
        if(0 <= now.se.fi - now.se.se)que.push(mk(now.fi + 1,mk(now.se.fi - now.se.se,now.se.se)));
    }
    printf("-1\n");
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:46:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i = 0; i < V[now.se.fi].size(); i++)
                            ~~^~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&b,&p);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2792 KB Output is correct
3 Correct 4 ms 2864 KB Output is correct
4 Correct 4 ms 2864 KB Output is correct
5 Correct 4 ms 2864 KB Output is correct
6 Correct 4 ms 2892 KB Output is correct
7 Correct 4 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2908 KB Output is correct
2 Correct 4 ms 2940 KB Output is correct
3 Correct 3 ms 2940 KB Output is correct
4 Correct 4 ms 2940 KB Output is correct
5 Correct 4 ms 2940 KB Output is correct
6 Correct 4 ms 2940 KB Output is correct
7 Correct 4 ms 2940 KB Output is correct
8 Correct 4 ms 2940 KB Output is correct
9 Correct 4 ms 2940 KB Output is correct
10 Correct 4 ms 2940 KB Output is correct
11 Correct 4 ms 2940 KB Output is correct
12 Correct 5 ms 2940 KB Output is correct
13 Correct 4 ms 2940 KB Output is correct
14 Correct 5 ms 3196 KB Output is correct
15 Correct 4 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3196 KB Output is correct
2 Correct 4 ms 3196 KB Output is correct
3 Correct 4 ms 3196 KB Output is correct
4 Correct 4 ms 3196 KB Output is correct
5 Correct 4 ms 3196 KB Output is correct
6 Correct 4 ms 3196 KB Output is correct
7 Correct 4 ms 3196 KB Output is correct
8 Correct 4 ms 3196 KB Output is correct
9 Correct 3 ms 3196 KB Output is correct
10 Correct 4 ms 3196 KB Output is correct
11 Correct 4 ms 3196 KB Output is correct
12 Correct 4 ms 3196 KB Output is correct
13 Correct 4 ms 3196 KB Output is correct
14 Correct 5 ms 3196 KB Output is correct
15 Correct 4 ms 3196 KB Output is correct
16 Correct 4 ms 3196 KB Output is correct
17 Correct 5 ms 3196 KB Output is correct
18 Correct 4 ms 3196 KB Output is correct
19 Correct 4 ms 3196 KB Output is correct
20 Correct 5 ms 3196 KB Output is correct
21 Correct 4 ms 3196 KB Output is correct
22 Correct 4 ms 3196 KB Output is correct
23 Correct 5 ms 3196 KB Output is correct
24 Correct 6 ms 3196 KB Output is correct
25 Correct 4 ms 3196 KB Output is correct
26 Correct 5 ms 3196 KB Output is correct
27 Correct 7 ms 3196 KB Output is correct
28 Correct 9 ms 3828 KB Output is correct
29 Correct 19 ms 5548 KB Output is correct
30 Correct 8 ms 5548 KB Output is correct
31 Correct 13 ms 5548 KB Output is correct
32 Correct 10 ms 5548 KB Output is correct
33 Correct 34 ms 8060 KB Output is correct
34 Correct 20 ms 8060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8060 KB Output is correct
2 Correct 4 ms 8060 KB Output is correct
3 Correct 4 ms 8060 KB Output is correct
4 Correct 3 ms 8060 KB Output is correct
5 Correct 3 ms 8060 KB Output is correct
6 Correct 4 ms 8060 KB Output is correct
7 Correct 3 ms 8060 KB Output is correct
8 Correct 3 ms 8060 KB Output is correct
9 Correct 3 ms 8060 KB Output is correct
10 Correct 4 ms 8060 KB Output is correct
11 Correct 4 ms 8060 KB Output is correct
12 Correct 4 ms 8060 KB Output is correct
13 Correct 4 ms 8060 KB Output is correct
14 Correct 5 ms 8060 KB Output is correct
15 Correct 4 ms 8060 KB Output is correct
16 Correct 4 ms 8060 KB Output is correct
17 Correct 4 ms 8060 KB Output is correct
18 Correct 4 ms 8060 KB Output is correct
19 Correct 4 ms 8060 KB Output is correct
20 Correct 5 ms 8060 KB Output is correct
21 Correct 4 ms 8060 KB Output is correct
22 Correct 5 ms 8060 KB Output is correct
23 Correct 5 ms 8060 KB Output is correct
24 Correct 6 ms 8060 KB Output is correct
25 Correct 4 ms 8060 KB Output is correct
26 Correct 5 ms 8060 KB Output is correct
27 Correct 5 ms 8060 KB Output is correct
28 Correct 9 ms 8060 KB Output is correct
29 Correct 18 ms 8060 KB Output is correct
30 Correct 8 ms 8060 KB Output is correct
31 Correct 13 ms 8060 KB Output is correct
32 Correct 9 ms 8060 KB Output is correct
33 Correct 35 ms 8060 KB Output is correct
34 Correct 20 ms 8060 KB Output is correct
35 Correct 13 ms 8060 KB Output is correct
36 Correct 5 ms 8060 KB Output is correct
37 Correct 10 ms 8060 KB Output is correct
38 Correct 13 ms 8060 KB Output is correct
39 Correct 12 ms 8060 KB Output is correct
40 Correct 12 ms 8060 KB Output is correct
41 Correct 12 ms 8060 KB Output is correct
42 Correct 10 ms 8060 KB Output is correct
43 Correct 10 ms 8060 KB Output is correct
44 Correct 11 ms 8060 KB Output is correct
45 Correct 241 ms 25864 KB Output is correct
46 Correct 97 ms 25864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 25864 KB Output is correct
2 Correct 4 ms 25864 KB Output is correct
3 Correct 3 ms 25864 KB Output is correct
4 Correct 3 ms 25864 KB Output is correct
5 Correct 3 ms 25864 KB Output is correct
6 Correct 4 ms 25864 KB Output is correct
7 Correct 3 ms 25864 KB Output is correct
8 Correct 3 ms 25864 KB Output is correct
9 Correct 3 ms 25864 KB Output is correct
10 Correct 4 ms 25864 KB Output is correct
11 Correct 4 ms 25864 KB Output is correct
12 Correct 4 ms 25864 KB Output is correct
13 Correct 4 ms 25864 KB Output is correct
14 Correct 5 ms 25864 KB Output is correct
15 Correct 4 ms 25864 KB Output is correct
16 Correct 4 ms 25864 KB Output is correct
17 Correct 5 ms 25864 KB Output is correct
18 Correct 4 ms 25864 KB Output is correct
19 Correct 4 ms 25864 KB Output is correct
20 Correct 4 ms 25864 KB Output is correct
21 Correct 4 ms 25864 KB Output is correct
22 Correct 4 ms 25864 KB Output is correct
23 Correct 5 ms 25864 KB Output is correct
24 Correct 6 ms 25864 KB Output is correct
25 Correct 4 ms 25864 KB Output is correct
26 Correct 5 ms 25864 KB Output is correct
27 Correct 5 ms 25864 KB Output is correct
28 Correct 9 ms 25864 KB Output is correct
29 Correct 18 ms 25864 KB Output is correct
30 Correct 8 ms 25864 KB Output is correct
31 Correct 12 ms 25864 KB Output is correct
32 Correct 9 ms 25864 KB Output is correct
33 Correct 36 ms 25864 KB Output is correct
34 Correct 21 ms 25864 KB Output is correct
35 Correct 14 ms 25864 KB Output is correct
36 Correct 5 ms 25864 KB Output is correct
37 Correct 10 ms 25864 KB Output is correct
38 Correct 13 ms 25864 KB Output is correct
39 Correct 12 ms 25864 KB Output is correct
40 Correct 12 ms 25864 KB Output is correct
41 Correct 12 ms 25864 KB Output is correct
42 Correct 10 ms 25864 KB Output is correct
43 Correct 10 ms 25864 KB Output is correct
44 Correct 11 ms 25864 KB Output is correct
45 Correct 230 ms 28560 KB Output is correct
46 Correct 97 ms 28560 KB Output is correct
47 Correct 12 ms 28560 KB Output is correct
48 Correct 11 ms 28560 KB Output is correct
49 Correct 11 ms 28560 KB Output is correct
50 Correct 9 ms 28560 KB Output is correct
51 Correct 31 ms 28560 KB Output is correct
52 Correct 36 ms 28560 KB Output is correct
53 Correct 16 ms 28560 KB Output is correct
54 Correct 7 ms 28560 KB Output is correct
55 Correct 9 ms 28560 KB Output is correct
56 Correct 24 ms 28560 KB Output is correct
57 Correct 4 ms 28560 KB Output is correct
58 Correct 26 ms 28560 KB Output is correct
59 Correct 23 ms 28560 KB Output is correct
60 Correct 22 ms 28560 KB Output is correct
61 Correct 22 ms 28560 KB Output is correct
62 Correct 272 ms 28568 KB Output is correct
63 Execution timed out 1089 ms 71952 KB Time limit exceeded
64 Halted 0 ms 0 KB -