답안 #312456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312456 2020-10-13T10:24:22 Z phathnv Jakarta Skyscrapers (APIO15_skyscraper) C++11
100 / 100
174 ms 97528 KB
#include <bits/stdc++.h>

#define X first
#define Y second
#define mp make_pair
#define task "SKY"

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 5e4 + 10;

int n, m, d[N];
ii a[N];
vector <int> atPos[N];

void input(){
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= m; i++)
        scanf("%d %d", &a[i].X, &a[i].Y);
}

set <int> S[N];
bool s2[2001][N];

bool mark(int b, int p){
    if (p <= 2000){
        if (s2[p][b])
            return 0;
        s2[p][b] = 1;
        return 1;
    }
    if (S[p].find(b) != S[p].end())
        return 0;
    S[p].insert(b);
    return 1;
}

iii Q[10000010];
int first = 1, last = 0;

void solve(){
    for(int i = 1; i <= m; i++)
        atPos[a[i].X].push_back(a[i].Y);

    int s = a[1].X;
    int t = a[2].X;
    memset(d, -1, sizeof(d));

    d[s] = 1;
    if (!atPos[s].empty())
        for(int i = 0; i < (int) atPos[s].size(); i++){
            int p = atPos[s][i];
            if (mark(s, p))
                Q[++last] = mp(0, mp(s, p));
        }

    while (first <= last){
        int u = Q[first].Y.X;
        int p = Q[first].Y.Y;
        int dist = Q[first].X;
        first++;

        if (u == t){
            cout << dist;
            return;
        }

        if (u - p >= 0)
            if (mark(u - p, p)){
                Q[++last] = mp(dist + 1, mp(u - p, p));
                if (d[u - p] == -1){
                    d[u - p] = 1;
                    if (!atPos[u - p].empty())
                        for(int i = 0; i < (int) atPos[u - p].size(); i++){
                            int x = atPos[u - p][i];
                            if (mark(u - p, x))
                                Q[++last] = mp(dist + 1, mp(u - p, x));
                        }
                }
            }

        if (u + p < n)
            if (mark(u + p, p)){
                Q[++last] = mp(dist + 1, mp(u + p, p));
                if (d[u + p] == -1){
                    d[u + p] = 1;
                    if (!atPos[u + p].empty())
                        for(int i = 0; i < (int) atPos[u + p].size(); i++){
                            int x = atPos[u + p][i];
                            if (mark(u + p, x))
                                Q[++last] = mp(dist + 1, mp(u + p, x));
                        }
                }
            }
    }
    cout << -1;
}

int main(){
    //freopen(task".inp", "r", stdin);
    //freopen(task".out", "w", stdout);
    input();
    solve();
}

Compilation message

skyscraper.cpp: In function 'void input()':
skyscraper.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         scanf("%d %d", &a[i].X, &a[i].Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4096 KB Output is correct
2 Correct 3 ms 4096 KB Output is correct
3 Correct 3 ms 4096 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 3 ms 4096 KB Output is correct
6 Correct 3 ms 4096 KB Output is correct
7 Correct 3 ms 4352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4096 KB Output is correct
2 Correct 3 ms 4096 KB Output is correct
3 Correct 3 ms 4096 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 3 ms 4096 KB Output is correct
6 Correct 3 ms 4096 KB Output is correct
7 Correct 3 ms 3968 KB Output is correct
8 Correct 3 ms 4096 KB Output is correct
9 Correct 3 ms 4096 KB Output is correct
10 Correct 3 ms 4480 KB Output is correct
11 Correct 4 ms 4480 KB Output is correct
12 Correct 3 ms 4224 KB Output is correct
13 Correct 3 ms 4096 KB Output is correct
14 Correct 4 ms 4480 KB Output is correct
15 Correct 4 ms 4352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4096 KB Output is correct
2 Correct 3 ms 4096 KB Output is correct
3 Correct 3 ms 4096 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 3 ms 4096 KB Output is correct
6 Correct 3 ms 4096 KB Output is correct
7 Correct 3 ms 4096 KB Output is correct
8 Correct 3 ms 4096 KB Output is correct
9 Correct 3 ms 4096 KB Output is correct
10 Correct 3 ms 4480 KB Output is correct
11 Correct 4 ms 4480 KB Output is correct
12 Correct 3 ms 4224 KB Output is correct
13 Correct 4 ms 4096 KB Output is correct
14 Correct 4 ms 4480 KB Output is correct
15 Correct 4 ms 4352 KB Output is correct
16 Correct 3 ms 4096 KB Output is correct
17 Correct 5 ms 6144 KB Output is correct
18 Correct 3 ms 4096 KB Output is correct
19 Correct 3 ms 4096 KB Output is correct
20 Correct 4 ms 4224 KB Output is correct
21 Correct 3 ms 4096 KB Output is correct
22 Correct 4 ms 4096 KB Output is correct
23 Correct 6 ms 7584 KB Output is correct
24 Correct 10 ms 10240 KB Output is correct
25 Correct 5 ms 5792 KB Output is correct
26 Correct 4 ms 4224 KB Output is correct
27 Correct 5 ms 5760 KB Output is correct
28 Correct 5 ms 5760 KB Output is correct
29 Correct 5 ms 4992 KB Output is correct
30 Correct 4 ms 4284 KB Output is correct
31 Correct 4 ms 4608 KB Output is correct
32 Correct 4 ms 4352 KB Output is correct
33 Correct 7 ms 5888 KB Output is correct
34 Correct 5 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4096 KB Output is correct
2 Correct 3 ms 4096 KB Output is correct
3 Correct 3 ms 4096 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 3 ms 4096 KB Output is correct
6 Correct 3 ms 4096 KB Output is correct
7 Correct 3 ms 4096 KB Output is correct
8 Correct 3 ms 4096 KB Output is correct
9 Correct 3 ms 4096 KB Output is correct
10 Correct 3 ms 4480 KB Output is correct
11 Correct 4 ms 4480 KB Output is correct
12 Correct 4 ms 4224 KB Output is correct
13 Correct 3 ms 4096 KB Output is correct
14 Correct 5 ms 4480 KB Output is correct
15 Correct 4 ms 4352 KB Output is correct
16 Correct 3 ms 4096 KB Output is correct
17 Correct 5 ms 6144 KB Output is correct
18 Correct 3 ms 4096 KB Output is correct
19 Correct 3 ms 4096 KB Output is correct
20 Correct 4 ms 4224 KB Output is correct
21 Correct 3 ms 4096 KB Output is correct
22 Correct 3 ms 4096 KB Output is correct
23 Correct 6 ms 7552 KB Output is correct
24 Correct 9 ms 10240 KB Output is correct
25 Correct 5 ms 5760 KB Output is correct
26 Correct 4 ms 4224 KB Output is correct
27 Correct 5 ms 5760 KB Output is correct
28 Correct 6 ms 5760 KB Output is correct
29 Correct 5 ms 4992 KB Output is correct
30 Correct 4 ms 4352 KB Output is correct
31 Correct 4 ms 4608 KB Output is correct
32 Correct 4 ms 4352 KB Output is correct
33 Correct 6 ms 5888 KB Output is correct
34 Correct 5 ms 5120 KB Output is correct
35 Correct 21 ms 15872 KB Output is correct
36 Correct 10 ms 9984 KB Output is correct
37 Correct 14 ms 10528 KB Output is correct
38 Correct 24 ms 17280 KB Output is correct
39 Correct 16 ms 9984 KB Output is correct
40 Correct 21 ms 15488 KB Output is correct
41 Correct 22 ms 16768 KB Output is correct
42 Correct 9 ms 4864 KB Output is correct
43 Correct 11 ms 6400 KB Output is correct
44 Correct 10 ms 4736 KB Output is correct
45 Correct 22 ms 11768 KB Output is correct
46 Correct 17 ms 9216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4096 KB Output is correct
2 Correct 3 ms 4096 KB Output is correct
3 Correct 3 ms 4096 KB Output is correct
4 Correct 4 ms 4096 KB Output is correct
5 Correct 3 ms 4224 KB Output is correct
6 Correct 3 ms 4096 KB Output is correct
7 Correct 3 ms 4096 KB Output is correct
8 Correct 3 ms 4096 KB Output is correct
9 Correct 3 ms 4096 KB Output is correct
10 Correct 3 ms 4480 KB Output is correct
11 Correct 4 ms 4480 KB Output is correct
12 Correct 4 ms 4224 KB Output is correct
13 Correct 3 ms 4096 KB Output is correct
14 Correct 4 ms 4480 KB Output is correct
15 Correct 4 ms 4352 KB Output is correct
16 Correct 3 ms 4096 KB Output is correct
17 Correct 5 ms 6144 KB Output is correct
18 Correct 3 ms 4096 KB Output is correct
19 Correct 3 ms 4096 KB Output is correct
20 Correct 4 ms 4224 KB Output is correct
21 Correct 4 ms 4096 KB Output is correct
22 Correct 3 ms 4096 KB Output is correct
23 Correct 6 ms 7552 KB Output is correct
24 Correct 9 ms 10240 KB Output is correct
25 Correct 5 ms 5760 KB Output is correct
26 Correct 4 ms 4224 KB Output is correct
27 Correct 5 ms 5760 KB Output is correct
28 Correct 5 ms 5760 KB Output is correct
29 Correct 5 ms 4992 KB Output is correct
30 Correct 3 ms 4352 KB Output is correct
31 Correct 4 ms 4608 KB Output is correct
32 Correct 4 ms 4480 KB Output is correct
33 Correct 6 ms 5888 KB Output is correct
34 Correct 5 ms 5120 KB Output is correct
35 Correct 21 ms 15872 KB Output is correct
36 Correct 9 ms 9984 KB Output is correct
37 Correct 15 ms 10496 KB Output is correct
38 Correct 24 ms 17272 KB Output is correct
39 Correct 17 ms 9984 KB Output is correct
40 Correct 21 ms 15480 KB Output is correct
41 Correct 23 ms 16768 KB Output is correct
42 Correct 9 ms 4864 KB Output is correct
43 Correct 12 ms 6400 KB Output is correct
44 Correct 10 ms 4736 KB Output is correct
45 Correct 22 ms 11776 KB Output is correct
46 Correct 17 ms 9088 KB Output is correct
47 Correct 33 ms 29944 KB Output is correct
48 Correct 12 ms 4864 KB Output is correct
49 Correct 11 ms 4864 KB Output is correct
50 Correct 9 ms 4736 KB Output is correct
51 Correct 40 ms 20340 KB Output is correct
52 Correct 43 ms 22008 KB Output is correct
53 Correct 15 ms 5664 KB Output is correct
54 Correct 3 ms 4224 KB Output is correct
55 Correct 4 ms 4352 KB Output is correct
56 Correct 14 ms 5888 KB Output is correct
57 Correct 4 ms 4224 KB Output is correct
58 Correct 11 ms 5888 KB Output is correct
59 Correct 11 ms 6016 KB Output is correct
60 Correct 11 ms 6016 KB Output is correct
61 Correct 15 ms 10496 KB Output is correct
62 Correct 54 ms 28256 KB Output is correct
63 Correct 114 ms 44920 KB Output is correct
64 Correct 102 ms 45816 KB Output is correct
65 Correct 129 ms 60280 KB Output is correct
66 Correct 174 ms 97528 KB Output is correct
67 Correct 96 ms 52856 KB Output is correct