Submission #45505

# Submission time Handle Problem Language Result Execution time Memory
45505 2018-04-14T19:19:42 Z dqhungdl Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 117656 KB
#include <bits/stdc++.h>
using namespace std;

const int lim=300;
typedef pair<int,int> ii;
int n,m,S,T,d[30005][305];
bool Visited[30005],Free[30005][305];
map<int,int> dd[30005];
map<int,bool> FFree[30005];
vector<int> g[30005];
queue<ii> Q;

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("TEST.INP","r",stdin);
    cin>>n>>m;
    int pos,step;
    for(int i=1;i<=m;i++)
    {
        cin>>pos>>step;
        g[pos+1].push_back(step);
        if(i==1)
            S=pos+1;
        if(i==2)
            T=pos+1;
    }
    for(int i=0; i<g[S].size(); i++)
    {
        if(g[S][i]<=lim)
            Free[S][g[S][i]]=true;
        else
            FFree[S][g[S][i]]=true;
        Q.push(ii(S,g[S][i]));
    }
    while(Q.size()>0)
    {
        int u=Q.front().first;
        int v=Q.front().second;
        int w;
        if(v<=lim)
            w=d[u][v];
        else
            w=dd[u][v];
        Q.pop();
        if(u==T)
        {
            cout<<w;
            return 0;
        }
        if(Visited[u]==false)
        {
            Visited[u]=true;
            for(int i=0; i<g[u].size(); i++)
            {
                if(u-g[u][i]>=1)
                {
                    if(g[u][i]<=lim&&Free[u-g[u][i]][g[u][i]]==false)
                    {
                        Free[u-g[u][i]][g[u][i]]=true;
                        d[u-g[u][i]][g[u][i]]=w+1;
                        Q.push(ii(u-g[u][i],g[u][i]));
                    }
                    else
                    if(g[u][i]>lim&&FFree[u-g[u][i]][g[u][i]]==false)
                    {
                        FFree[u-g[u][i]][g[u][i]]=true;
                        dd[u-g[u][i]][g[u][i]]=w+1;
                        Q.push(ii(u-g[u][i],g[u][i]));
                    }
                }
                if(u+g[u][i]<=n)
                {
                    if(g[u][i]<=lim&&Free[u+g[u][i]][g[u][i]]==false)
                    {
                        Free[u+g[u][i]][g[u][i]]=true;
                        d[u+g[u][i]][g[u][i]]=w+1;
                        Q.push(ii(u+g[u][i],g[u][i]));
                    }
                    else
                    if(g[u][i]>lim&&FFree[u+g[u][i]][g[u][i]]==false)
                    {
                        FFree[u+g[u][i]][g[u][i]]=true;
                        dd[u+g[u][i]][g[u][i]]=w+1;
                        Q.push(ii(u+g[u][i],g[u][i]));
                    }
                }
            }
        }
        if(u-v>=1)
        {
            if(v<=lim&&Free[u-v][v]==false)
            {
                Free[u-v][v]=true;
                d[u-v][v]=w+1;
                Q.push(ii(u-v,v));
            }
            else
            if(v>lim&&FFree[u-v][v]==false)
            {
                FFree[u-v][v]=true;
                dd[u-v][v]=w+1;
                Q.push(ii(u-v,v));
            }
        }
        if(u+v<=n)
        {
            if(v<=lim&&Free[u+v][v]==false)
            {
                Free[u+v][v]=true;
                d[u+v][v]=w+1;
                Q.push(ii(u+v,v));
            }
            else
            if(v>lim&&FFree[u+v][v]==false)
            {
                FFree[u+v][v]=true;
                dd[u+v][v]=w+1;
                Q.push(ii(u+v,v));
            }
        }
    }
    cout<<-1;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<g[S].size(); i++)
                  ~^~~~~~~~~~~~
skyscraper.cpp:54:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i=0; i<g[u].size(); i++)
                          ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3832 KB Output is correct
2 Correct 4 ms 3944 KB Output is correct
3 Correct 4 ms 3944 KB Output is correct
4 Correct 4 ms 3944 KB Output is correct
5 Correct 4 ms 3944 KB Output is correct
6 Correct 4 ms 4012 KB Output is correct
7 Correct 4 ms 4012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4056 KB Output is correct
2 Correct 4 ms 4056 KB Output is correct
3 Correct 4 ms 4128 KB Output is correct
4 Correct 4 ms 4128 KB Output is correct
5 Correct 4 ms 4128 KB Output is correct
6 Correct 4 ms 4144 KB Output is correct
7 Correct 4 ms 4144 KB Output is correct
8 Correct 4 ms 4144 KB Output is correct
9 Correct 5 ms 4196 KB Output is correct
10 Correct 5 ms 4196 KB Output is correct
11 Correct 5 ms 4324 KB Output is correct
12 Correct 5 ms 4324 KB Output is correct
13 Correct 6 ms 4324 KB Output is correct
14 Correct 6 ms 4324 KB Output is correct
15 Correct 5 ms 4324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4324 KB Output is correct
2 Correct 4 ms 4324 KB Output is correct
3 Correct 5 ms 4324 KB Output is correct
4 Correct 4 ms 4324 KB Output is correct
5 Correct 4 ms 4324 KB Output is correct
6 Correct 4 ms 4324 KB Output is correct
7 Correct 5 ms 4324 KB Output is correct
8 Correct 5 ms 4324 KB Output is correct
9 Correct 5 ms 4324 KB Output is correct
10 Correct 5 ms 4324 KB Output is correct
11 Correct 5 ms 4336 KB Output is correct
12 Correct 5 ms 4336 KB Output is correct
13 Correct 5 ms 4336 KB Output is correct
14 Correct 5 ms 4460 KB Output is correct
15 Correct 5 ms 4460 KB Output is correct
16 Correct 4 ms 4460 KB Output is correct
17 Correct 6 ms 5372 KB Output is correct
18 Correct 5 ms 5372 KB Output is correct
19 Correct 5 ms 5372 KB Output is correct
20 Correct 7 ms 7168 KB Output is correct
21 Correct 5 ms 7168 KB Output is correct
22 Correct 5 ms 7168 KB Output is correct
23 Correct 8 ms 7168 KB Output is correct
24 Correct 9 ms 7292 KB Output is correct
25 Correct 5 ms 7292 KB Output is correct
26 Correct 7 ms 7292 KB Output is correct
27 Correct 7 ms 7292 KB Output is correct
28 Correct 8 ms 7344 KB Output is correct
29 Correct 9 ms 7344 KB Output is correct
30 Correct 7 ms 7344 KB Output is correct
31 Correct 8 ms 7344 KB Output is correct
32 Correct 7 ms 7344 KB Output is correct
33 Correct 11 ms 7344 KB Output is correct
34 Correct 9 ms 7344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7344 KB Output is correct
2 Correct 4 ms 7344 KB Output is correct
3 Correct 4 ms 7344 KB Output is correct
4 Correct 4 ms 7344 KB Output is correct
5 Correct 4 ms 7344 KB Output is correct
6 Correct 4 ms 7344 KB Output is correct
7 Correct 4 ms 7344 KB Output is correct
8 Correct 5 ms 7344 KB Output is correct
9 Correct 5 ms 7344 KB Output is correct
10 Correct 5 ms 7344 KB Output is correct
11 Correct 5 ms 7344 KB Output is correct
12 Correct 5 ms 7344 KB Output is correct
13 Correct 6 ms 7344 KB Output is correct
14 Correct 6 ms 7344 KB Output is correct
15 Correct 5 ms 7344 KB Output is correct
16 Correct 4 ms 7344 KB Output is correct
17 Correct 6 ms 7344 KB Output is correct
18 Correct 5 ms 7344 KB Output is correct
19 Correct 5 ms 7344 KB Output is correct
20 Correct 7 ms 7344 KB Output is correct
21 Correct 5 ms 7344 KB Output is correct
22 Correct 5 ms 7344 KB Output is correct
23 Correct 7 ms 7344 KB Output is correct
24 Correct 8 ms 7344 KB Output is correct
25 Correct 5 ms 7344 KB Output is correct
26 Correct 7 ms 7344 KB Output is correct
27 Correct 7 ms 7344 KB Output is correct
28 Correct 8 ms 7344 KB Output is correct
29 Correct 8 ms 7344 KB Output is correct
30 Correct 7 ms 7344 KB Output is correct
31 Correct 8 ms 7344 KB Output is correct
32 Correct 9 ms 7344 KB Output is correct
33 Correct 11 ms 7344 KB Output is correct
34 Correct 9 ms 7344 KB Output is correct
35 Correct 22 ms 8316 KB Output is correct
36 Correct 8 ms 8316 KB Output is correct
37 Correct 19 ms 8444 KB Output is correct
38 Correct 25 ms 9340 KB Output is correct
39 Correct 12 ms 9340 KB Output is correct
40 Correct 14 ms 9340 KB Output is correct
41 Correct 16 ms 9340 KB Output is correct
42 Correct 13 ms 9340 KB Output is correct
43 Correct 13 ms 9340 KB Output is correct
44 Correct 13 ms 9340 KB Output is correct
45 Correct 33 ms 9340 KB Output is correct
46 Correct 21 ms 9340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9340 KB Output is correct
2 Correct 4 ms 9340 KB Output is correct
3 Correct 4 ms 9340 KB Output is correct
4 Correct 4 ms 9340 KB Output is correct
5 Correct 4 ms 9340 KB Output is correct
6 Correct 5 ms 9340 KB Output is correct
7 Correct 4 ms 9340 KB Output is correct
8 Correct 4 ms 9340 KB Output is correct
9 Correct 5 ms 9340 KB Output is correct
10 Correct 5 ms 9340 KB Output is correct
11 Correct 5 ms 9340 KB Output is correct
12 Correct 5 ms 9340 KB Output is correct
13 Correct 5 ms 9340 KB Output is correct
14 Correct 5 ms 9340 KB Output is correct
15 Correct 5 ms 9340 KB Output is correct
16 Correct 5 ms 9340 KB Output is correct
17 Correct 6 ms 9340 KB Output is correct
18 Correct 5 ms 9340 KB Output is correct
19 Correct 4 ms 9340 KB Output is correct
20 Correct 7 ms 9340 KB Output is correct
21 Correct 5 ms 9340 KB Output is correct
22 Correct 4 ms 9340 KB Output is correct
23 Correct 7 ms 9340 KB Output is correct
24 Correct 10 ms 9340 KB Output is correct
25 Correct 5 ms 9340 KB Output is correct
26 Correct 7 ms 9340 KB Output is correct
27 Correct 8 ms 9340 KB Output is correct
28 Correct 10 ms 9340 KB Output is correct
29 Correct 9 ms 9340 KB Output is correct
30 Correct 7 ms 9340 KB Output is correct
31 Correct 8 ms 9340 KB Output is correct
32 Correct 7 ms 9340 KB Output is correct
33 Correct 11 ms 9340 KB Output is correct
34 Correct 9 ms 9340 KB Output is correct
35 Correct 24 ms 9340 KB Output is correct
36 Correct 7 ms 9340 KB Output is correct
37 Correct 17 ms 9340 KB Output is correct
38 Correct 24 ms 9340 KB Output is correct
39 Correct 12 ms 9340 KB Output is correct
40 Correct 13 ms 9340 KB Output is correct
41 Correct 16 ms 9340 KB Output is correct
42 Correct 12 ms 9340 KB Output is correct
43 Correct 13 ms 9340 KB Output is correct
44 Correct 14 ms 9340 KB Output is correct
45 Correct 29 ms 9340 KB Output is correct
46 Correct 31 ms 9340 KB Output is correct
47 Correct 28 ms 14484 KB Output is correct
48 Correct 12 ms 14484 KB Output is correct
49 Correct 11 ms 14484 KB Output is correct
50 Correct 9 ms 14484 KB Output is correct
51 Correct 56 ms 18940 KB Output is correct
52 Correct 60 ms 22272 KB Output is correct
53 Correct 33 ms 22272 KB Output is correct
54 Correct 45 ms 48952 KB Output is correct
55 Correct 40 ms 49016 KB Output is correct
56 Correct 51 ms 49852 KB Output is correct
57 Correct 6 ms 49852 KB Output is correct
58 Correct 59 ms 49852 KB Output is correct
59 Correct 52 ms 49852 KB Output is correct
60 Correct 51 ms 49852 KB Output is correct
61 Correct 50 ms 49852 KB Output is correct
62 Correct 243 ms 66432 KB Output is correct
63 Execution timed out 1079 ms 117656 KB Time limit exceeded
64 Halted 0 ms 0 KB -