Submission #31139

# Submission time Handle Problem Language Result Execution time Memory
31139 2017-08-11T03:20:58 Z nibnalin Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
36 ms 2180 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

const int inf = int(1e9)+5, maxn = int(2e3)+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;
                                                                     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
8 Correct 0 ms 2048 KB Output is correct
9 Correct 0 ms 2048 KB Output is correct
10 Correct 0 ms 2048 KB Output is correct
11 Correct 26 ms 2180 KB Output is correct
12 Correct 19 ms 2180 KB Output is correct
13 Correct 29 ms 2180 KB Output is correct
14 Correct 19 ms 2180 KB Output is correct
15 Correct 23 ms 2180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
8 Correct 0 ms 2048 KB Output is correct
9 Correct 0 ms 2048 KB Output is correct
10 Correct 0 ms 2048 KB Output is correct
11 Correct 19 ms 2180 KB Output is correct
12 Correct 19 ms 2180 KB Output is correct
13 Correct 19 ms 2180 KB Output is correct
14 Correct 19 ms 2180 KB Output is correct
15 Correct 19 ms 2180 KB Output is correct
16 Correct 0 ms 2048 KB Output is correct
17 Correct 26 ms 2180 KB Output is correct
18 Correct 0 ms 2048 KB Output is correct
19 Correct 0 ms 2048 KB Output is correct
20 Correct 33 ms 2180 KB Output is correct
21 Correct 0 ms 2048 KB Output is correct
22 Correct 0 ms 2048 KB Output is correct
23 Correct 3 ms 2048 KB Output is correct
24 Correct 23 ms 2180 KB Output is correct
25 Correct 26 ms 2180 KB Output is correct
26 Correct 16 ms 2180 KB Output is correct
27 Correct 23 ms 2180 KB Output is correct
28 Correct 23 ms 2048 KB Output is correct
29 Correct 3 ms 2048 KB Output is correct
30 Correct 0 ms 2048 KB Output is correct
31 Correct 0 ms 2048 KB Output is correct
32 Correct 3 ms 2048 KB Output is correct
33 Correct 26 ms 2180 KB Output is correct
34 Correct 23 ms 2180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
8 Correct 0 ms 2048 KB Output is correct
9 Correct 0 ms 2048 KB Output is correct
10 Correct 0 ms 2048 KB Output is correct
11 Correct 29 ms 2180 KB Output is correct
12 Correct 23 ms 2180 KB Output is correct
13 Correct 33 ms 2180 KB Output is correct
14 Correct 36 ms 2180 KB Output is correct
15 Correct 23 ms 2180 KB Output is correct
16 Correct 0 ms 2048 KB Output is correct
17 Correct 26 ms 2180 KB Output is correct
18 Correct 0 ms 2048 KB Output is correct
19 Correct 0 ms 2048 KB Output is correct
20 Correct 26 ms 2180 KB Output is correct
21 Correct 0 ms 2048 KB Output is correct
22 Correct 0 ms 2048 KB Output is correct
23 Correct 3 ms 2048 KB Output is correct
24 Correct 26 ms 2180 KB Output is correct
25 Correct 23 ms 2180 KB Output is correct
26 Correct 19 ms 2180 KB Output is correct
27 Correct 19 ms 2180 KB Output is correct
28 Correct 26 ms 2048 KB Output is correct
29 Correct 3 ms 2048 KB Output is correct
30 Correct 0 ms 2048 KB Output is correct
31 Correct 3 ms 2048 KB Output is correct
32 Correct 0 ms 2048 KB Output is correct
33 Correct 26 ms 2180 KB Output is correct
34 Correct 23 ms 2180 KB Output is correct
35 Runtime error 0 ms 2048 KB Execution killed because of forbidden syscall futex (202)
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
8 Correct 0 ms 2048 KB Output is correct
9 Correct 0 ms 2048 KB Output is correct
10 Correct 0 ms 2048 KB Output is correct
11 Correct 19 ms 2180 KB Output is correct
12 Correct 19 ms 2180 KB Output is correct
13 Correct 19 ms 2180 KB Output is correct
14 Correct 19 ms 2180 KB Output is correct
15 Correct 16 ms 2180 KB Output is correct
16 Correct 0 ms 2048 KB Output is correct
17 Correct 16 ms 2180 KB Output is correct
18 Correct 0 ms 2048 KB Output is correct
19 Correct 0 ms 2048 KB Output is correct
20 Correct 19 ms 2180 KB Output is correct
21 Correct 0 ms 2048 KB Output is correct
22 Correct 0 ms 2048 KB Output is correct
23 Correct 3 ms 2048 KB Output is correct
24 Correct 16 ms 2180 KB Output is correct
25 Correct 19 ms 2180 KB Output is correct
26 Correct 19 ms 2180 KB Output is correct
27 Correct 19 ms 2180 KB Output is correct
28 Correct 19 ms 2048 KB Output is correct
29 Correct 3 ms 2048 KB Output is correct
30 Correct 0 ms 2048 KB Output is correct
31 Correct 0 ms 2048 KB Output is correct
32 Correct 0 ms 2048 KB Output is correct
33 Correct 23 ms 2180 KB Output is correct
34 Correct 23 ms 2180 KB Output is correct
35 Runtime error 0 ms 2048 KB Execution killed because of forbidden syscall futex (202)
36 Halted 0 ms 0 KB -