답안 #45446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45446 2018-04-14T05:58:22 Z RayaBurong25_1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
339 ms 32636 KB
#include <stdio.h>
#include <vector>
#include <set>
#include <algorithm>
#define INF 1000000007
int B[30005], P[30005];
int AdjList[2005][2005];
int abs(int a)
{
    return (a < 0)?-a:a;
}
int Min[30005];
typedef struct node node;
struct node
{
    int u, w;
};
bool operator<(node a, node b)
{
    return (a.w < b.w || (a.w == b.w && a.u < b.u));
}
std::set<node> Q;
int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    int i, j;
    for (i = 0; i < M; i++)
        scanf("%d %d", &B[i], &P[i]);
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            AdjList[i][j] = INF;
    for (i = 0; i < M; i++)
    {
        for (j = 0; j < N; j++)
        {
            if (B[i] == j) continue;
            if (abs(B[i] - j)%P[i] == 0)
                AdjList[B[i]][j] = std::min(AdjList[B[i]][j], abs(B[i] - j)/P[i]);
        }
    }
    for (i = 0; i < N; i++)
        Min[i] = INF;
    Min[B[0]] = 0;
    Q.insert({B[0], 0});
    node p;
    int v, w, s;
    while (!Q.empty())
    {
        p = *Q.begin();
        Q.erase(Q.begin());
        // printf("pop %d %d\n", p.u, p.w);
        if (p.u == B[1])
        {
            printf("%d", p.w);
            return 0;
        }

        for (i = 0; i < N; i++)
        {
            w = AdjList[p.u][i];
            if (p.w + w < Min[i])
            {
                if (Min[i] != INF)
                    Q.erase({i, Min[i]});
                Min[i] = p.w + w;
                Q.insert({i, Min[i]});
            }
        }
    }
    printf("-1");
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:47:9: warning: unused variable 'v' [-Wunused-variable]
     int v, w, s;
         ^
skyscraper.cpp:47:15: warning: unused variable 's' [-Wunused-variable]
     int v, w, s;
               ^
skyscraper.cpp:26: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:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &B[i], &P[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 2 ms 428 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 672 KB Output is correct
2 Correct 2 ms 672 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 2 ms 1020 KB Output is correct
11 Correct 3 ms 1020 KB Output is correct
12 Correct 4 ms 1076 KB Output is correct
13 Correct 3 ms 1076 KB Output is correct
14 Correct 4 ms 1076 KB Output is correct
15 Correct 4 ms 1076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1076 KB Output is correct
2 Correct 2 ms 1076 KB Output is correct
3 Correct 2 ms 1076 KB Output is correct
4 Correct 2 ms 1076 KB Output is correct
5 Correct 2 ms 1076 KB Output is correct
6 Correct 2 ms 1076 KB Output is correct
7 Correct 2 ms 1076 KB Output is correct
8 Correct 2 ms 1076 KB Output is correct
9 Correct 2 ms 1076 KB Output is correct
10 Correct 2 ms 1076 KB Output is correct
11 Correct 5 ms 1076 KB Output is correct
12 Correct 3 ms 1076 KB Output is correct
13 Correct 4 ms 1076 KB Output is correct
14 Correct 3 ms 1076 KB Output is correct
15 Correct 5 ms 1076 KB Output is correct
16 Correct 3 ms 1532 KB Output is correct
17 Correct 13 ms 5756 KB Output is correct
18 Correct 20 ms 14332 KB Output is correct
19 Correct 19 ms 16252 KB Output is correct
20 Correct 40 ms 16380 KB Output is correct
21 Correct 6 ms 16380 KB Output is correct
22 Correct 19 ms 16380 KB Output is correct
23 Correct 22 ms 16380 KB Output is correct
24 Correct 35 ms 16380 KB Output is correct
25 Correct 35 ms 16380 KB Output is correct
26 Correct 37 ms 16380 KB Output is correct
27 Correct 37 ms 16380 KB Output is correct
28 Correct 37 ms 16380 KB Output is correct
29 Correct 28 ms 16384 KB Output is correct
30 Correct 21 ms 16384 KB Output is correct
31 Correct 25 ms 16384 KB Output is correct
32 Correct 26 ms 16384 KB Output is correct
33 Correct 40 ms 16384 KB Output is correct
34 Correct 41 ms 16384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16384 KB Output is correct
2 Correct 2 ms 16384 KB Output is correct
3 Correct 2 ms 16384 KB Output is correct
4 Correct 2 ms 16384 KB Output is correct
5 Correct 2 ms 16384 KB Output is correct
6 Correct 2 ms 16384 KB Output is correct
7 Correct 2 ms 16384 KB Output is correct
8 Correct 2 ms 16384 KB Output is correct
9 Correct 2 ms 16384 KB Output is correct
10 Correct 2 ms 16384 KB Output is correct
11 Correct 3 ms 16384 KB Output is correct
12 Correct 3 ms 16384 KB Output is correct
13 Correct 3 ms 16384 KB Output is correct
14 Correct 3 ms 16384 KB Output is correct
15 Correct 5 ms 16384 KB Output is correct
16 Correct 3 ms 16384 KB Output is correct
17 Correct 18 ms 16384 KB Output is correct
18 Correct 20 ms 16384 KB Output is correct
19 Correct 18 ms 16384 KB Output is correct
20 Correct 38 ms 16384 KB Output is correct
21 Correct 5 ms 16384 KB Output is correct
22 Correct 23 ms 16384 KB Output is correct
23 Correct 24 ms 16384 KB Output is correct
24 Correct 35 ms 16384 KB Output is correct
25 Correct 44 ms 16384 KB Output is correct
26 Correct 37 ms 16384 KB Output is correct
27 Correct 37 ms 16384 KB Output is correct
28 Correct 38 ms 16384 KB Output is correct
29 Correct 27 ms 16384 KB Output is correct
30 Correct 22 ms 16384 KB Output is correct
31 Correct 25 ms 16384 KB Output is correct
32 Correct 27 ms 16384 KB Output is correct
33 Correct 40 ms 16384 KB Output is correct
34 Correct 39 ms 16384 KB Output is correct
35 Correct 193 ms 16384 KB Output is correct
36 Correct 35 ms 16384 KB Output is correct
37 Correct 206 ms 16384 KB Output is correct
38 Correct 310 ms 16508 KB Output is correct
39 Correct 310 ms 16508 KB Output is correct
40 Correct 314 ms 16508 KB Output is correct
41 Correct 312 ms 16508 KB Output is correct
42 Correct 302 ms 16636 KB Output is correct
43 Correct 291 ms 16636 KB Output is correct
44 Correct 292 ms 16636 KB Output is correct
45 Correct 316 ms 16636 KB Output is correct
46 Correct 312 ms 16636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16636 KB Output is correct
2 Correct 2 ms 16636 KB Output is correct
3 Correct 2 ms 16636 KB Output is correct
4 Correct 2 ms 16636 KB Output is correct
5 Correct 2 ms 16636 KB Output is correct
6 Correct 2 ms 16636 KB Output is correct
7 Correct 2 ms 16636 KB Output is correct
8 Correct 2 ms 16636 KB Output is correct
9 Correct 2 ms 16636 KB Output is correct
10 Correct 2 ms 16636 KB Output is correct
11 Correct 3 ms 16636 KB Output is correct
12 Correct 3 ms 16636 KB Output is correct
13 Correct 3 ms 16636 KB Output is correct
14 Correct 3 ms 16636 KB Output is correct
15 Correct 3 ms 16636 KB Output is correct
16 Correct 3 ms 16636 KB Output is correct
17 Correct 14 ms 16636 KB Output is correct
18 Correct 21 ms 16636 KB Output is correct
19 Correct 19 ms 16636 KB Output is correct
20 Correct 38 ms 16636 KB Output is correct
21 Correct 5 ms 16636 KB Output is correct
22 Correct 19 ms 16636 KB Output is correct
23 Correct 22 ms 16636 KB Output is correct
24 Correct 47 ms 16636 KB Output is correct
25 Correct 39 ms 16636 KB Output is correct
26 Correct 42 ms 16636 KB Output is correct
27 Correct 40 ms 16636 KB Output is correct
28 Correct 42 ms 16636 KB Output is correct
29 Correct 33 ms 16636 KB Output is correct
30 Correct 29 ms 16636 KB Output is correct
31 Correct 27 ms 16636 KB Output is correct
32 Correct 25 ms 16636 KB Output is correct
33 Correct 40 ms 16636 KB Output is correct
34 Correct 40 ms 16636 KB Output is correct
35 Correct 190 ms 16636 KB Output is correct
36 Correct 42 ms 16636 KB Output is correct
37 Correct 212 ms 16636 KB Output is correct
38 Correct 307 ms 16636 KB Output is correct
39 Correct 303 ms 16636 KB Output is correct
40 Correct 322 ms 16636 KB Output is correct
41 Correct 321 ms 16636 KB Output is correct
42 Correct 292 ms 16636 KB Output is correct
43 Correct 301 ms 16636 KB Output is correct
44 Correct 301 ms 16636 KB Output is correct
45 Correct 322 ms 16636 KB Output is correct
46 Correct 339 ms 16636 KB Output is correct
47 Runtime error 48 ms 32636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Halted 0 ms 0 KB -