Submission #31141

# Submission time Handle Problem Language Result Execution time Memory
31141 2017-08-11T03:34:33 Z nibnalin Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 5308 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][2];
vector<int> doge[maxn];

// 0 => doge
// 1 => skyscraper

int dist(int x, int y)
{
    int ret = abs(B[x]-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][0] = inf;
        doge[B[i]].push_back(i);
    }
    for(int i = 0;i < n;i++) D[i][1] = inf;

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

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

        if(top.second.second)
        {
            for(auto it: doge[top.second.first])
            {
                if(top.first < D[it][0])
                {
                    if(D[it][0] != inf) Q.erase({D[it][0], {it, 0}});
                    D[it][0] = top.first;
                    Q.insert({D[it][0], {it, 0}});
                }
            }
        }
        else
        {
            for(int i = 0;i < n;i++)
            {
                int c = dist(top.second.first, i);
                if(top.first+c < D[i][1])
                {
                    if(D[i][1] != inf) Q.erase({D[i][1], {i, 1}});
                    D[i][1] = top.first+c;
                    Q.insert({D[i][1], {i, 1}});
                }
            }
        }
    }

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

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26: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:29:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &B[i], &P[i]), D[i][0] = inf;
                                                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3196 KB Output is correct
2 Correct 0 ms 3196 KB Output is correct
3 Correct 0 ms 3196 KB Output is correct
4 Correct 0 ms 3196 KB Output is correct
5 Correct 0 ms 3196 KB Output is correct
6 Correct 0 ms 3196 KB Output is correct
7 Correct 0 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3196 KB Output is correct
2 Correct 0 ms 3196 KB Output is correct
3 Correct 0 ms 3196 KB Output is correct
4 Correct 0 ms 3196 KB Output is correct
5 Correct 0 ms 3196 KB Output is correct
6 Correct 0 ms 3196 KB Output is correct
7 Correct 0 ms 3196 KB Output is correct
8 Correct 0 ms 3196 KB Output is correct
9 Correct 0 ms 3196 KB Output is correct
10 Correct 0 ms 3196 KB Output is correct
11 Correct 0 ms 3328 KB Output is correct
12 Correct 3 ms 3328 KB Output is correct
13 Correct 3 ms 3328 KB Output is correct
14 Correct 0 ms 3328 KB Output is correct
15 Correct 0 ms 3328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3196 KB Output is correct
2 Correct 0 ms 3196 KB Output is correct
3 Correct 0 ms 3196 KB Output is correct
4 Correct 0 ms 3196 KB Output is correct
5 Correct 0 ms 3196 KB Output is correct
6 Correct 0 ms 3196 KB Output is correct
7 Correct 0 ms 3196 KB Output is correct
8 Correct 0 ms 3196 KB Output is correct
9 Correct 0 ms 3196 KB Output is correct
10 Correct 0 ms 3196 KB Output is correct
11 Correct 0 ms 3328 KB Output is correct
12 Correct 0 ms 3328 KB Output is correct
13 Correct 0 ms 3328 KB Output is correct
14 Correct 0 ms 3328 KB Output is correct
15 Correct 0 ms 3328 KB Output is correct
16 Correct 0 ms 3196 KB Output is correct
17 Correct 6 ms 3328 KB Output is correct
18 Correct 0 ms 3196 KB Output is correct
19 Correct 0 ms 3196 KB Output is correct
20 Correct 19 ms 3460 KB Output is correct
21 Correct 0 ms 3196 KB Output is correct
22 Correct 0 ms 3196 KB Output is correct
23 Correct 6 ms 3328 KB Output is correct
24 Correct 26 ms 3328 KB Output is correct
25 Correct 23 ms 3328 KB Output is correct
26 Correct 16 ms 3328 KB Output is correct
27 Correct 23 ms 3328 KB Output is correct
28 Correct 23 ms 3328 KB Output is correct
29 Correct 9 ms 3328 KB Output is correct
30 Correct 3 ms 3328 KB Output is correct
31 Correct 6 ms 3328 KB Output is correct
32 Correct 6 ms 3328 KB Output is correct
33 Correct 29 ms 3460 KB Output is correct
34 Correct 23 ms 3460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3196 KB Output is correct
2 Correct 0 ms 3196 KB Output is correct
3 Correct 0 ms 3196 KB Output is correct
4 Correct 0 ms 3196 KB Output is correct
5 Correct 0 ms 3196 KB Output is correct
6 Correct 0 ms 3196 KB Output is correct
7 Correct 0 ms 3196 KB Output is correct
8 Correct 0 ms 3196 KB Output is correct
9 Correct 0 ms 3196 KB Output is correct
10 Correct 0 ms 3196 KB Output is correct
11 Correct 3 ms 3328 KB Output is correct
12 Correct 3 ms 3328 KB Output is correct
13 Correct 3 ms 3328 KB Output is correct
14 Correct 3 ms 3328 KB Output is correct
15 Correct 0 ms 3328 KB Output is correct
16 Correct 0 ms 3196 KB Output is correct
17 Correct 13 ms 3328 KB Output is correct
18 Correct 0 ms 3196 KB Output is correct
19 Correct 0 ms 3196 KB Output is correct
20 Correct 23 ms 3460 KB Output is correct
21 Correct 0 ms 3196 KB Output is correct
22 Correct 0 ms 3196 KB Output is correct
23 Correct 6 ms 3328 KB Output is correct
24 Correct 19 ms 3328 KB Output is correct
25 Correct 23 ms 3328 KB Output is correct
26 Correct 19 ms 3328 KB Output is correct
27 Correct 26 ms 3328 KB Output is correct
28 Correct 19 ms 3328 KB Output is correct
29 Correct 13 ms 3328 KB Output is correct
30 Correct 3 ms 3328 KB Output is correct
31 Correct 6 ms 3328 KB Output is correct
32 Correct 6 ms 3328 KB Output is correct
33 Correct 26 ms 3460 KB Output is correct
34 Correct 23 ms 3460 KB Output is correct
35 Correct 243 ms 4384 KB Output is correct
36 Correct 33 ms 3328 KB Output is correct
37 Correct 213 ms 4120 KB Output is correct
38 Correct 336 ms 4780 KB Output is correct
39 Correct 323 ms 4780 KB Output is correct
40 Correct 359 ms 4648 KB Output is correct
41 Correct 349 ms 4648 KB Output is correct
42 Correct 336 ms 5256 KB Output is correct
43 Correct 323 ms 5256 KB Output is correct
44 Correct 329 ms 5156 KB Output is correct
45 Correct 306 ms 5308 KB Output is correct
46 Correct 329 ms 5308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3196 KB Output is correct
2 Correct 0 ms 3196 KB Output is correct
3 Correct 0 ms 3196 KB Output is correct
4 Correct 0 ms 3196 KB Output is correct
5 Correct 0 ms 3196 KB Output is correct
6 Correct 0 ms 3196 KB Output is correct
7 Correct 0 ms 3196 KB Output is correct
8 Correct 0 ms 3196 KB Output is correct
9 Correct 0 ms 3196 KB Output is correct
10 Correct 0 ms 3196 KB Output is correct
11 Correct 3 ms 3328 KB Output is correct
12 Correct 3 ms 3328 KB Output is correct
13 Correct 3 ms 3328 KB Output is correct
14 Correct 3 ms 3328 KB Output is correct
15 Correct 3 ms 3328 KB Output is correct
16 Correct 0 ms 3196 KB Output is correct
17 Correct 9 ms 3328 KB Output is correct
18 Correct 0 ms 3196 KB Output is correct
19 Correct 0 ms 3196 KB Output is correct
20 Correct 19 ms 3460 KB Output is correct
21 Correct 0 ms 3196 KB Output is correct
22 Correct 0 ms 3196 KB Output is correct
23 Correct 9 ms 3328 KB Output is correct
24 Correct 16 ms 3328 KB Output is correct
25 Correct 23 ms 3328 KB Output is correct
26 Correct 19 ms 3328 KB Output is correct
27 Correct 23 ms 3328 KB Output is correct
28 Correct 23 ms 3328 KB Output is correct
29 Correct 9 ms 3328 KB Output is correct
30 Correct 3 ms 3328 KB Output is correct
31 Correct 6 ms 3328 KB Output is correct
32 Correct 6 ms 3328 KB Output is correct
33 Correct 23 ms 3460 KB Output is correct
34 Correct 26 ms 3460 KB Output is correct
35 Correct 213 ms 4384 KB Output is correct
36 Correct 29 ms 3328 KB Output is correct
37 Correct 206 ms 4120 KB Output is correct
38 Correct 316 ms 4780 KB Output is correct
39 Correct 339 ms 4780 KB Output is correct
40 Correct 329 ms 4648 KB Output is correct
41 Correct 323 ms 4648 KB Output is correct
42 Correct 319 ms 5256 KB Output is correct
43 Correct 289 ms 5256 KB Output is correct
44 Correct 303 ms 5156 KB Output is correct
45 Correct 343 ms 5308 KB Output is correct
46 Correct 336 ms 5308 KB Output is correct
47 Execution timed out 1000 ms 4384 KB Execution timed out
48 Halted 0 ms 0 KB -