답안 #208572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208572 2020-03-11T16:53:31 Z DodgeBallMan Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
253 ms 64748 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 3e4 + 10;
const int M = 2e3 + 5;
int n, m, d[N], st, en, inf = 1e9;
bool chk[N][M];
vector<int> g[N];
priority_queue<pii, vector<pii>, greater<pii>> q;

int main()
{
    fill( d, d+N, inf );
    scanf("%d %d",&n,&m);
    for( int i = 0, a, b ; i < m ; i++ ) {
        scanf("%d %d",&a,&b);
        g[a].emplace_back( b );
        if( i == 0 ) st = a;
        else if( i == 1 ) en = a;
    }
    for( int i = 0 ; i < n ; i++ ) {
        sort( g[i].begin(), g[i].end() );
        g[i].resize(unique(g[i].begin(), g[i].end())-g[i].begin());
    } 
    q.emplace( d[st] = 0, st );
    while( !q.empty() ) {
        pii now = q.top(); q.pop();
        if( d[now.y] != now.x ) continue;
        for( int p : g[now.y] ) {
            for( int i = now.y + p, cnt = 1 ; i < n ; i += p, cnt++ ) {
                if( p < M && chk[i][p] ) break ;
                if( d[i] > d[now.y] + cnt ) {
                    q.emplace( d[i] = d[now.y] + cnt, i );
                    if( p < M ) chk[i][p] = true;
                }
            }
            for( int i = now.y - p, cnt = 1 ; i >= 0 ; i -= p, cnt++ ) {
                if( p < M && chk[i][p] ) break ;
                if( d[i] > d[now.y] + cnt ) {
                    q.emplace( d[i] = d[now.y] + cnt, i );
                    if( p < M ) chk[i][p] = true;
                }
            }
        }
    }
    printf("%d",d[en]==inf?-1:d[en]);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:18: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:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1144 KB Output is correct
2 Correct 5 ms 1144 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1148 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 5 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1144 KB Output is correct
2 Correct 5 ms 1144 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 5 ms 1148 KB Output is correct
7 Correct 5 ms 1144 KB Output is correct
8 Correct 5 ms 1148 KB Output is correct
9 Correct 5 ms 1272 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 6 ms 1400 KB Output is correct
12 Correct 6 ms 1400 KB Output is correct
13 Correct 6 ms 1400 KB Output is correct
14 Correct 6 ms 1400 KB Output is correct
15 Correct 6 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1144 KB Output is correct
2 Correct 5 ms 1144 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 5 ms 1144 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 5 ms 1272 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 6 ms 1400 KB Output is correct
12 Correct 6 ms 1400 KB Output is correct
13 Correct 6 ms 1400 KB Output is correct
14 Correct 6 ms 1400 KB Output is correct
15 Correct 6 ms 1400 KB Output is correct
16 Correct 6 ms 1144 KB Output is correct
17 Correct 7 ms 2680 KB Output is correct
18 Correct 5 ms 1144 KB Output is correct
19 Correct 5 ms 1144 KB Output is correct
20 Correct 9 ms 5244 KB Output is correct
21 Correct 5 ms 1144 KB Output is correct
22 Correct 5 ms 1144 KB Output is correct
23 Correct 8 ms 4344 KB Output is correct
24 Correct 10 ms 4860 KB Output is correct
25 Correct 9 ms 5112 KB Output is correct
26 Correct 8 ms 5112 KB Output is correct
27 Correct 9 ms 5112 KB Output is correct
28 Correct 9 ms 5112 KB Output is correct
29 Correct 10 ms 5368 KB Output is correct
30 Correct 9 ms 5112 KB Output is correct
31 Correct 9 ms 5240 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
33 Correct 13 ms 5496 KB Output is correct
34 Correct 12 ms 5496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1144 KB Output is correct
2 Correct 5 ms 1144 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 5 ms 1144 KB Output is correct
8 Correct 5 ms 1144 KB Output is correct
9 Correct 5 ms 1272 KB Output is correct
10 Correct 5 ms 1272 KB Output is correct
11 Correct 6 ms 1400 KB Output is correct
12 Correct 6 ms 1400 KB Output is correct
13 Correct 5 ms 1400 KB Output is correct
14 Correct 6 ms 1400 KB Output is correct
15 Correct 6 ms 1400 KB Output is correct
16 Correct 5 ms 1144 KB Output is correct
17 Correct 8 ms 2680 KB Output is correct
18 Correct 5 ms 1144 KB Output is correct
19 Correct 6 ms 1144 KB Output is correct
20 Correct 9 ms 5112 KB Output is correct
21 Correct 5 ms 1144 KB Output is correct
22 Correct 6 ms 1144 KB Output is correct
23 Correct 10 ms 4344 KB Output is correct
24 Correct 9 ms 4984 KB Output is correct
25 Correct 9 ms 5112 KB Output is correct
26 Correct 8 ms 5112 KB Output is correct
27 Correct 8 ms 5112 KB Output is correct
28 Correct 9 ms 5112 KB Output is correct
29 Correct 10 ms 5240 KB Output is correct
30 Correct 8 ms 5112 KB Output is correct
31 Correct 10 ms 5240 KB Output is correct
32 Correct 9 ms 5112 KB Output is correct
33 Correct 12 ms 5500 KB Output is correct
34 Correct 12 ms 5496 KB Output is correct
35 Correct 16 ms 4216 KB Output is correct
36 Correct 8 ms 3320 KB Output is correct
37 Correct 15 ms 5244 KB Output is correct
38 Correct 20 ms 5496 KB Output is correct
39 Correct 19 ms 5368 KB Output is correct
40 Correct 19 ms 5368 KB Output is correct
41 Correct 19 ms 5496 KB Output is correct
42 Correct 14 ms 5368 KB Output is correct
43 Correct 14 ms 5368 KB Output is correct
44 Correct 14 ms 5368 KB Output is correct
45 Correct 20 ms 5624 KB Output is correct
46 Correct 20 ms 5624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1144 KB Output is correct
2 Correct 5 ms 1144 KB Output is correct
3 Correct 5 ms 1144 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1176 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 5 ms 1144 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 5 ms 1272 KB Output is correct
10 Correct 6 ms 1400 KB Output is correct
11 Correct 6 ms 1400 KB Output is correct
12 Correct 6 ms 1400 KB Output is correct
13 Correct 7 ms 1400 KB Output is correct
14 Correct 6 ms 1400 KB Output is correct
15 Correct 6 ms 1400 KB Output is correct
16 Correct 6 ms 1144 KB Output is correct
17 Correct 7 ms 2680 KB Output is correct
18 Correct 5 ms 1144 KB Output is correct
19 Correct 5 ms 1144 KB Output is correct
20 Correct 8 ms 5240 KB Output is correct
21 Correct 5 ms 1144 KB Output is correct
22 Correct 5 ms 1144 KB Output is correct
23 Correct 8 ms 4344 KB Output is correct
24 Correct 9 ms 4856 KB Output is correct
25 Correct 10 ms 5112 KB Output is correct
26 Correct 8 ms 5112 KB Output is correct
27 Correct 8 ms 5112 KB Output is correct
28 Correct 9 ms 5112 KB Output is correct
29 Correct 10 ms 5240 KB Output is correct
30 Correct 9 ms 5112 KB Output is correct
31 Correct 9 ms 5244 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
33 Correct 13 ms 5496 KB Output is correct
34 Correct 12 ms 5496 KB Output is correct
35 Correct 16 ms 4216 KB Output is correct
36 Correct 8 ms 3320 KB Output is correct
37 Correct 17 ms 5240 KB Output is correct
38 Correct 20 ms 5368 KB Output is correct
39 Correct 19 ms 5496 KB Output is correct
40 Correct 19 ms 5368 KB Output is correct
41 Correct 19 ms 5372 KB Output is correct
42 Correct 13 ms 5368 KB Output is correct
43 Correct 13 ms 5368 KB Output is correct
44 Correct 14 ms 5244 KB Output is correct
45 Correct 21 ms 5628 KB Output is correct
46 Correct 21 ms 5624 KB Output is correct
47 Correct 55 ms 26360 KB Output is correct
48 Correct 14 ms 1528 KB Output is correct
49 Correct 13 ms 1528 KB Output is correct
50 Correct 10 ms 1528 KB Output is correct
51 Correct 76 ms 61176 KB Output is correct
52 Correct 77 ms 61176 KB Output is correct
53 Correct 59 ms 61176 KB Output is correct
54 Correct 44 ms 60280 KB Output is correct
55 Correct 43 ms 60280 KB Output is correct
56 Correct 54 ms 61300 KB Output is correct
57 Correct 87 ms 61292 KB Output is correct
58 Correct 49 ms 60536 KB Output is correct
59 Correct 52 ms 60536 KB Output is correct
60 Correct 56 ms 60664 KB Output is correct
61 Correct 52 ms 60668 KB Output is correct
62 Correct 43 ms 24312 KB Output is correct
63 Correct 113 ms 62572 KB Output is correct
64 Correct 130 ms 62572 KB Output is correct
65 Correct 161 ms 62576 KB Output is correct
66 Correct 239 ms 64612 KB Output is correct
67 Correct 253 ms 64748 KB Output is correct