답안 #49496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49496 2018-05-29T19:37:15 Z updown1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
911 ms 16452 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, M)
#define ffa ffi ffj
#define w cout
#define e "\n"
#define s <<" "<<
#define pb push_back
#define mp make_pair
#define a first
#define b second
/// 500,000,000
const int MAXN = 30000, INF = 1000000000000000000;
/// Global Variables
int N, M, dist[MAXN], B[MAXN], P[MAXN];
bool vis[MAXN];
vector<int> dogs[MAXN];
priority_queue<pair<int, int> > next1; /// (-dist, loc)

void go(int loc) {
    vis[loc] = true;
    For (i, 0, dogs[loc].size()) {
        int x = dogs[loc][i];
        for (int j=loc+P[x], add = 1; j<N; j+= P[x], add++) if (dist[loc]+add < dist[j]) {
            dist[j] = min(dist[j], dist[loc]+add);
            next1.push(mp(-dist[j], j));
        }
        for (int j=loc-P[x], add = 1; j>= 0; j-= P[x], add++) if (dist[loc]+add < dist[j]) {
            dist[j] = min(dist[j], dist[loc]+add);
            next1.push(mp(-dist[j], j));
        }
    }
}

main() {
    //ifstream cin("test.in");
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    ffi dist[i] = INF;
    ffj {
        cin >> B[j] >> P[j];
        dogs[B[j]].pb(j);
    }
    next1.push(mp(0, B[0]));
    dist[B[0]] = 0;
    while (!next1.empty()) {
        int i = next1.top().b; next1.pop();
        if (!vis[i]) go(i);
    }
    if (dist[B[1]] == INF) w<< -1<<e;
    else w<< dist[B[1]]<<e;
}

Compilation message

skyscraper.cpp: In function 'void go(ll)':
skyscraper.cpp:5:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define For(i, a, b) for(int i=a; i<b; i++)
skyscraper.cpp:26:10:
     For (i, 0, dogs[loc].size()) {
          ~~~~~~~~~~~~~~~~~~~~~~     
skyscraper.cpp:26:5: note: in expansion of macro 'For'
     For (i, 0, dogs[loc].size()) {
     ^~~
skyscraper.cpp: At global scope:
skyscraper.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 4 ms 1124 KB Output is correct
3 Correct 3 ms 1124 KB Output is correct
4 Correct 3 ms 1216 KB Output is correct
5 Correct 3 ms 1276 KB Output is correct
6 Correct 3 ms 1276 KB Output is correct
7 Correct 2 ms 1276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1276 KB Output is correct
2 Correct 2 ms 1276 KB Output is correct
3 Correct 3 ms 1276 KB Output is correct
4 Correct 4 ms 1276 KB Output is correct
5 Correct 6 ms 1316 KB Output is correct
6 Correct 4 ms 1316 KB Output is correct
7 Correct 3 ms 1316 KB Output is correct
8 Correct 3 ms 1360 KB Output is correct
9 Correct 3 ms 1360 KB Output is correct
10 Correct 4 ms 1360 KB Output is correct
11 Correct 3 ms 1380 KB Output is correct
12 Correct 4 ms 1380 KB Output is correct
13 Correct 4 ms 1380 KB Output is correct
14 Correct 4 ms 1380 KB Output is correct
15 Correct 4 ms 1380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1380 KB Output is correct
2 Correct 2 ms 1380 KB Output is correct
3 Correct 2 ms 1380 KB Output is correct
4 Correct 2 ms 1380 KB Output is correct
5 Correct 3 ms 1380 KB Output is correct
6 Correct 4 ms 1380 KB Output is correct
7 Correct 4 ms 1380 KB Output is correct
8 Correct 3 ms 1380 KB Output is correct
9 Correct 2 ms 1380 KB Output is correct
10 Correct 3 ms 1380 KB Output is correct
11 Correct 3 ms 1380 KB Output is correct
12 Correct 5 ms 1380 KB Output is correct
13 Correct 5 ms 1380 KB Output is correct
14 Correct 4 ms 1380 KB Output is correct
15 Correct 3 ms 1380 KB Output is correct
16 Correct 3 ms 1380 KB Output is correct
17 Correct 4 ms 1380 KB Output is correct
18 Correct 6 ms 1412 KB Output is correct
19 Correct 3 ms 1412 KB Output is correct
20 Correct 7 ms 1412 KB Output is correct
21 Correct 3 ms 1412 KB Output is correct
22 Correct 4 ms 1412 KB Output is correct
23 Correct 4 ms 1412 KB Output is correct
24 Correct 5 ms 1452 KB Output is correct
25 Correct 4 ms 1592 KB Output is correct
26 Correct 7 ms 1592 KB Output is correct
27 Correct 7 ms 1592 KB Output is correct
28 Correct 3 ms 1592 KB Output is correct
29 Correct 5 ms 1720 KB Output is correct
30 Correct 4 ms 1720 KB Output is correct
31 Correct 4 ms 1720 KB Output is correct
32 Correct 4 ms 1720 KB Output is correct
33 Correct 9 ms 1748 KB Output is correct
34 Correct 6 ms 1896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1896 KB Output is correct
2 Correct 3 ms 1896 KB Output is correct
3 Correct 2 ms 1896 KB Output is correct
4 Correct 3 ms 1896 KB Output is correct
5 Correct 3 ms 1896 KB Output is correct
6 Correct 24 ms 1896 KB Output is correct
7 Correct 2 ms 1896 KB Output is correct
8 Correct 3 ms 1896 KB Output is correct
9 Correct 3 ms 1896 KB Output is correct
10 Correct 3 ms 1896 KB Output is correct
11 Correct 3 ms 1896 KB Output is correct
12 Correct 3 ms 1896 KB Output is correct
13 Correct 4 ms 1896 KB Output is correct
14 Correct 4 ms 1896 KB Output is correct
15 Correct 4 ms 1896 KB Output is correct
16 Correct 4 ms 1896 KB Output is correct
17 Correct 4 ms 1896 KB Output is correct
18 Correct 3 ms 1896 KB Output is correct
19 Correct 4 ms 1896 KB Output is correct
20 Correct 8 ms 1896 KB Output is correct
21 Correct 3 ms 1896 KB Output is correct
22 Correct 3 ms 1896 KB Output is correct
23 Correct 3 ms 1896 KB Output is correct
24 Correct 5 ms 1896 KB Output is correct
25 Correct 4 ms 1896 KB Output is correct
26 Correct 7 ms 1896 KB Output is correct
27 Correct 6 ms 1896 KB Output is correct
28 Correct 10 ms 1896 KB Output is correct
29 Correct 5 ms 1896 KB Output is correct
30 Correct 5 ms 1896 KB Output is correct
31 Correct 4 ms 1896 KB Output is correct
32 Correct 4 ms 1896 KB Output is correct
33 Correct 6 ms 1944 KB Output is correct
34 Correct 5 ms 2048 KB Output is correct
35 Correct 12 ms 2736 KB Output is correct
36 Correct 5 ms 2736 KB Output is correct
37 Correct 11 ms 2912 KB Output is correct
38 Correct 14 ms 3404 KB Output is correct
39 Correct 21 ms 3716 KB Output is correct
40 Correct 15 ms 4032 KB Output is correct
41 Correct 13 ms 4220 KB Output is correct
42 Correct 90 ms 4228 KB Output is correct
43 Correct 86 ms 4440 KB Output is correct
44 Correct 79 ms 4552 KB Output is correct
45 Correct 14 ms 4988 KB Output is correct
46 Correct 13 ms 5224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5224 KB Output is correct
2 Correct 3 ms 5224 KB Output is correct
3 Correct 3 ms 5224 KB Output is correct
4 Correct 2 ms 5224 KB Output is correct
5 Correct 3 ms 5224 KB Output is correct
6 Correct 2 ms 5224 KB Output is correct
7 Correct 3 ms 5224 KB Output is correct
8 Correct 5 ms 5224 KB Output is correct
9 Correct 2 ms 5224 KB Output is correct
10 Correct 2 ms 5224 KB Output is correct
11 Correct 3 ms 5224 KB Output is correct
12 Correct 3 ms 5224 KB Output is correct
13 Correct 3 ms 5224 KB Output is correct
14 Correct 3 ms 5224 KB Output is correct
15 Correct 3 ms 5224 KB Output is correct
16 Correct 3 ms 5224 KB Output is correct
17 Correct 4 ms 5224 KB Output is correct
18 Correct 2 ms 5224 KB Output is correct
19 Correct 2 ms 5224 KB Output is correct
20 Correct 7 ms 5224 KB Output is correct
21 Correct 3 ms 5224 KB Output is correct
22 Correct 3 ms 5224 KB Output is correct
23 Correct 4 ms 5224 KB Output is correct
24 Correct 4 ms 5224 KB Output is correct
25 Correct 3 ms 5224 KB Output is correct
26 Correct 6 ms 5224 KB Output is correct
27 Correct 6 ms 5224 KB Output is correct
28 Correct 4 ms 5224 KB Output is correct
29 Correct 5 ms 5224 KB Output is correct
30 Correct 5 ms 5224 KB Output is correct
31 Correct 5 ms 5224 KB Output is correct
32 Correct 4 ms 5224 KB Output is correct
33 Correct 5 ms 5224 KB Output is correct
34 Correct 5 ms 5224 KB Output is correct
35 Correct 10 ms 5412 KB Output is correct
36 Correct 5 ms 5412 KB Output is correct
37 Correct 10 ms 5488 KB Output is correct
38 Correct 20 ms 6032 KB Output is correct
39 Correct 18 ms 6296 KB Output is correct
40 Correct 16 ms 6620 KB Output is correct
41 Correct 24 ms 6824 KB Output is correct
42 Correct 66 ms 6832 KB Output is correct
43 Correct 67 ms 7040 KB Output is correct
44 Correct 70 ms 7160 KB Output is correct
45 Correct 13 ms 7584 KB Output is correct
46 Correct 13 ms 7796 KB Output is correct
47 Correct 25 ms 9032 KB Output is correct
48 Correct 11 ms 9032 KB Output is correct
49 Correct 11 ms 9032 KB Output is correct
50 Correct 11 ms 9032 KB Output is correct
51 Correct 71 ms 11564 KB Output is correct
52 Correct 48 ms 11564 KB Output is correct
53 Correct 25 ms 11564 KB Output is correct
54 Correct 5 ms 11564 KB Output is correct
55 Correct 6 ms 11564 KB Output is correct
56 Correct 907 ms 11564 KB Output is correct
57 Correct 85 ms 13584 KB Output is correct
58 Correct 911 ms 13584 KB Output is correct
59 Correct 817 ms 13584 KB Output is correct
60 Correct 816 ms 13584 KB Output is correct
61 Correct 800 ms 13584 KB Output is correct
62 Correct 15 ms 13584 KB Output is correct
63 Correct 34 ms 13584 KB Output is correct
64 Correct 39 ms 13824 KB Output is correct
65 Correct 41 ms 14044 KB Output is correct
66 Correct 57 ms 16172 KB Output is correct
67 Correct 59 ms 16452 KB Output is correct