답안 #679855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679855 2023-01-09T12:52:05 Z 79brue Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
249 ms 94812 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int G = 175;

struct dat{
    int x, doge, dist;
    dat(){}
    dat(int x, int doge, int dist): x(x), doge(doge), dist(dist){}
};

int n, k;
bool visited1[30002][180];
bool visited2[30002][180];
bool started[30002];
int st[30002], a[30002], b[30002], idx[30002];
vector<int> lst[30002];

dat que[10000002];
int que_size, que_front;

dat pop(){
    return que[que_front++];
}

void push(dat tmp){
    que[que_size++] = tmp;
}

inline bool chk(int d, int x){
    if(b[d] <= G) return visited1[x][b[d]];
    return visited2[idx[d]][x/b[d]];
}

inline void mark(int d, int x){
    if(b[d] <= G) visited1[x][b[d]] = 1;
    else visited2[idx[d]][x/b[d]] = 1;
}

inline void go(dat &tmp){
    int r = b[tmp.doge];
    if(tmp.x - r >= 0 && !chk(tmp.doge, tmp.x - r)) mark(tmp.doge, tmp.x-r), push(dat(tmp.x - r, tmp.doge, tmp.dist+1));
    if(tmp.x + r <  n && !chk(tmp.doge, tmp.x + r)) mark(tmp.doge, tmp.x+r), push(dat(tmp.x + r, tmp.doge, tmp.dist+1));
}

int main(){
    scanf("%d %d", &n, &k);
    for(int i=1; i<=k; i++){
        scanf("%d %d", &st[i], &b[i]);
        a[i] = st[i] % b[i];
        lst[st[i]].push_back(i);
    }

    vector<pair<int, int> > vec;
    for(int i=1; i<=k; i++) vec.push_back(make_pair(a[i], b[i]));
    sort(vec.begin(), vec.end());
    for(int i=1; i<=k; i++){
        int tmp = lower_bound(vec.begin(), vec.end(), make_pair(a[i], b[i])) - vec.begin() + 1;
        idx[i] = tmp;
    }

    push(dat(st[1], 1, 0));
    mark(1, st[1]);
    while(que_size != que_front){
        dat tmp = pop();
//        printf("x: %d, doge: %d, dist: %d\n", tmp.x, tmp.doge, tmp.dist);
        if(tmp.doge == 2){
            printf("%d", tmp.dist);
            return 0;
        }
        if(!started[tmp.x]){
            started[tmp.x] = 1;
            for(int d: lst[tmp.x]){
                if(d == 2){
                    printf("%d", tmp.dist);
                    return 0;
                }
                if(chk(d, tmp.x)) continue;
                mark(d, tmp.x);
                dat tmp2 = dat(tmp.x, d, tmp.dist);
                go(tmp2);
            }
        }
        go(tmp);
    }

    printf("-1");
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d %d", &st[i], &b[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 1084 KB Output is correct
12 Correct 1 ms 1216 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 1 ms 1492 KB Output is correct
24 Correct 2 ms 1748 KB Output is correct
25 Correct 2 ms 1364 KB Output is correct
26 Correct 1 ms 1492 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 3 ms 1920 KB Output is correct
29 Correct 2 ms 2132 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 2 ms 1748 KB Output is correct
32 Correct 2 ms 1620 KB Output is correct
33 Correct 5 ms 2772 KB Output is correct
34 Correct 3 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1492 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 1 ms 1492 KB Output is correct
24 Correct 3 ms 1748 KB Output is correct
25 Correct 2 ms 1364 KB Output is correct
26 Correct 1 ms 1492 KB Output is correct
27 Correct 2 ms 1620 KB Output is correct
28 Correct 3 ms 2004 KB Output is correct
29 Correct 2 ms 2132 KB Output is correct
30 Correct 2 ms 1492 KB Output is correct
31 Correct 2 ms 1748 KB Output is correct
32 Correct 2 ms 1620 KB Output is correct
33 Correct 5 ms 2772 KB Output is correct
34 Correct 3 ms 2132 KB Output is correct
35 Correct 15 ms 6864 KB Output is correct
36 Correct 3 ms 2132 KB Output is correct
37 Correct 11 ms 5456 KB Output is correct
38 Correct 19 ms 7880 KB Output is correct
39 Correct 15 ms 2388 KB Output is correct
40 Correct 14 ms 3540 KB Output is correct
41 Correct 19 ms 7880 KB Output is correct
42 Correct 9 ms 2256 KB Output is correct
43 Correct 7 ms 2332 KB Output is correct
44 Correct 7 ms 2304 KB Output is correct
45 Correct 31 ms 10968 KB Output is correct
46 Correct 22 ms 8404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 2 ms 1504 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 2 ms 1492 KB Output is correct
24 Correct 2 ms 1756 KB Output is correct
25 Correct 2 ms 1364 KB Output is correct
26 Correct 2 ms 1492 KB Output is correct
27 Correct 1 ms 1428 KB Output is correct
28 Correct 2 ms 2004 KB Output is correct
29 Correct 2 ms 2004 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 2 ms 1748 KB Output is correct
32 Correct 2 ms 1620 KB Output is correct
33 Correct 5 ms 2772 KB Output is correct
34 Correct 3 ms 2132 KB Output is correct
35 Correct 16 ms 6952 KB Output is correct
36 Correct 3 ms 2132 KB Output is correct
37 Correct 12 ms 5624 KB Output is correct
38 Correct 17 ms 7892 KB Output is correct
39 Correct 14 ms 2408 KB Output is correct
40 Correct 15 ms 3464 KB Output is correct
41 Correct 17 ms 7896 KB Output is correct
42 Correct 6 ms 2256 KB Output is correct
43 Correct 6 ms 2384 KB Output is correct
44 Correct 7 ms 2388 KB Output is correct
45 Correct 30 ms 10908 KB Output is correct
46 Correct 23 ms 8348 KB Output is correct
47 Correct 17 ms 8640 KB Output is correct
48 Correct 14 ms 2160 KB Output is correct
49 Correct 10 ms 2132 KB Output is correct
50 Correct 7 ms 1876 KB Output is correct
51 Correct 22 ms 10708 KB Output is correct
52 Correct 26 ms 11220 KB Output is correct
53 Correct 16 ms 4692 KB Output is correct
54 Correct 4 ms 6484 KB Output is correct
55 Correct 4 ms 6640 KB Output is correct
56 Correct 13 ms 8376 KB Output is correct
57 Correct 2 ms 1364 KB Output is correct
58 Correct 11 ms 8016 KB Output is correct
59 Correct 12 ms 7916 KB Output is correct
60 Correct 11 ms 7872 KB Output is correct
61 Correct 11 ms 8028 KB Output is correct
62 Correct 35 ms 18132 KB Output is correct
63 Correct 96 ms 38872 KB Output is correct
64 Correct 113 ms 43472 KB Output is correct
65 Correct 172 ms 59088 KB Output is correct
66 Correct 249 ms 94812 KB Output is correct
67 Correct 145 ms 52168 KB Output is correct