답안 #31140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31140 2017-08-11T03:22:01 Z nibnalin Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 3564 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

const int inf = int(1e9)+5, maxn = int(3e4)+5;

int B[maxn], P[maxn], D[maxn];

int dist(int x, int y)
{
    int ret = abs(B[x]-B[y]);
    if(ret%P[x] == 0) return ret/P[x];
    else return inf;
}

int main(void)
{
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0;i < m;i++) scanf("%d%d", &B[i], &P[i]), D[i] = inf;

    set<pair<int, int>> Q;
    D[0] = 0;
    Q.insert({0, 0});

    while(!Q.empty())
    {
        pair<int, int> top = *Q.begin();
        Q.erase(Q.begin());
        //cout << top.second << "\n";

        for(int i = 0;i < m;i++)
        {
            if(i == top.second) continue;

            int c = dist(top.second, i);
            if(top.first+c < D[i])
            {
                if(D[i] != inf) Q.erase({D[i], i});
                D[i] = top.first+c;
                Q.insert({D[i], i});
            }
        }
    }

    printf("%d\n", (D[1] >= inf)?-1:D[1]);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
                          ^
skyscraper.cpp:23:69: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0;i < m;i++) scanf("%d%d", &B[i], &P[i]), D[i] = inf;
                                                                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2376 KB Output is correct
2 Correct 0 ms 2376 KB Output is correct
3 Correct 0 ms 2376 KB Output is correct
4 Correct 0 ms 2376 KB Output is correct
5 Correct 0 ms 2376 KB Output is correct
6 Correct 0 ms 2376 KB Output is correct
7 Correct 0 ms 2376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2376 KB Output is correct
2 Correct 0 ms 2376 KB Output is correct
3 Correct 0 ms 2376 KB Output is correct
4 Correct 0 ms 2376 KB Output is correct
5 Correct 0 ms 2376 KB Output is correct
6 Correct 0 ms 2376 KB Output is correct
7 Correct 0 ms 2376 KB Output is correct
8 Correct 0 ms 2376 KB Output is correct
9 Correct 0 ms 2376 KB Output is correct
10 Correct 0 ms 2376 KB Output is correct
11 Correct 23 ms 2508 KB Output is correct
12 Correct 19 ms 2508 KB Output is correct
13 Correct 19 ms 2508 KB Output is correct
14 Correct 19 ms 2508 KB Output is correct
15 Correct 23 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2376 KB Output is correct
2 Correct 0 ms 2376 KB Output is correct
3 Correct 0 ms 2376 KB Output is correct
4 Correct 0 ms 2376 KB Output is correct
5 Correct 0 ms 2376 KB Output is correct
6 Correct 0 ms 2376 KB Output is correct
7 Correct 0 ms 2376 KB Output is correct
8 Correct 0 ms 2376 KB Output is correct
9 Correct 0 ms 2376 KB Output is correct
10 Correct 0 ms 2376 KB Output is correct
11 Correct 23 ms 2508 KB Output is correct
12 Correct 19 ms 2508 KB Output is correct
13 Correct 19 ms 2508 KB Output is correct
14 Correct 19 ms 2508 KB Output is correct
15 Correct 19 ms 2508 KB Output is correct
16 Correct 0 ms 2376 KB Output is correct
17 Correct 16 ms 2508 KB Output is correct
18 Correct 0 ms 2376 KB Output is correct
19 Correct 0 ms 2376 KB Output is correct
20 Correct 23 ms 2508 KB Output is correct
21 Correct 0 ms 2376 KB Output is correct
22 Correct 0 ms 2376 KB Output is correct
23 Correct 3 ms 2376 KB Output is correct
24 Correct 23 ms 2508 KB Output is correct
25 Correct 29 ms 2508 KB Output is correct
26 Correct 19 ms 2508 KB Output is correct
27 Correct 23 ms 2508 KB Output is correct
28 Correct 29 ms 2376 KB Output is correct
29 Correct 3 ms 2376 KB Output is correct
30 Correct 0 ms 2376 KB Output is correct
31 Correct 0 ms 2376 KB Output is correct
32 Correct 0 ms 2376 KB Output is correct
33 Correct 26 ms 2508 KB Output is correct
34 Correct 33 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2376 KB Output is correct
2 Correct 0 ms 2376 KB Output is correct
3 Correct 0 ms 2376 KB Output is correct
4 Correct 0 ms 2376 KB Output is correct
5 Correct 0 ms 2376 KB Output is correct
6 Correct 0 ms 2376 KB Output is correct
7 Correct 0 ms 2376 KB Output is correct
8 Correct 0 ms 2376 KB Output is correct
9 Correct 0 ms 2376 KB Output is correct
10 Correct 0 ms 2376 KB Output is correct
11 Correct 23 ms 2508 KB Output is correct
12 Correct 23 ms 2508 KB Output is correct
13 Correct 23 ms 2508 KB Output is correct
14 Correct 29 ms 2508 KB Output is correct
15 Correct 29 ms 2508 KB Output is correct
16 Correct 0 ms 2376 KB Output is correct
17 Correct 26 ms 2508 KB Output is correct
18 Correct 0 ms 2376 KB Output is correct
19 Correct 0 ms 2376 KB Output is correct
20 Correct 29 ms 2508 KB Output is correct
21 Correct 0 ms 2376 KB Output is correct
22 Correct 0 ms 2376 KB Output is correct
23 Correct 6 ms 2376 KB Output is correct
24 Correct 16 ms 2508 KB Output is correct
25 Correct 19 ms 2508 KB Output is correct
26 Correct 26 ms 2508 KB Output is correct
27 Correct 19 ms 2508 KB Output is correct
28 Correct 23 ms 2376 KB Output is correct
29 Correct 3 ms 2376 KB Output is correct
30 Correct 0 ms 2376 KB Output is correct
31 Correct 0 ms 2376 KB Output is correct
32 Correct 0 ms 2376 KB Output is correct
33 Correct 19 ms 2508 KB Output is correct
34 Correct 23 ms 2508 KB Output is correct
35 Execution timed out 1000 ms 3564 KB Execution timed out
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2376 KB Output is correct
2 Correct 0 ms 2376 KB Output is correct
3 Correct 0 ms 2376 KB Output is correct
4 Correct 0 ms 2376 KB Output is correct
5 Correct 0 ms 2376 KB Output is correct
6 Correct 0 ms 2376 KB Output is correct
7 Correct 0 ms 2376 KB Output is correct
8 Correct 0 ms 2376 KB Output is correct
9 Correct 0 ms 2376 KB Output is correct
10 Correct 0 ms 2376 KB Output is correct
11 Correct 29 ms 2508 KB Output is correct
12 Correct 23 ms 2508 KB Output is correct
13 Correct 29 ms 2508 KB Output is correct
14 Correct 29 ms 2508 KB Output is correct
15 Correct 29 ms 2508 KB Output is correct
16 Correct 0 ms 2376 KB Output is correct
17 Correct 23 ms 2508 KB Output is correct
18 Correct 0 ms 2376 KB Output is correct
19 Correct 0 ms 2376 KB Output is correct
20 Correct 19 ms 2508 KB Output is correct
21 Correct 0 ms 2376 KB Output is correct
22 Correct 0 ms 2376 KB Output is correct
23 Correct 3 ms 2376 KB Output is correct
24 Correct 19 ms 2508 KB Output is correct
25 Correct 23 ms 2508 KB Output is correct
26 Correct 19 ms 2508 KB Output is correct
27 Correct 19 ms 2508 KB Output is correct
28 Correct 19 ms 2376 KB Output is correct
29 Correct 3 ms 2376 KB Output is correct
30 Correct 0 ms 2376 KB Output is correct
31 Correct 0 ms 2376 KB Output is correct
32 Correct 0 ms 2376 KB Output is correct
33 Correct 23 ms 2508 KB Output is correct
34 Correct 33 ms 2508 KB Output is correct
35 Execution timed out 1000 ms 3564 KB Execution timed out
36 Halted 0 ms 0 KB -