Submission #122436

# Submission time Handle Problem Language Result Execution time Memory
122436 2019-06-28T08:17:53 Z IOrtroiii Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
160 ms 75984 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 30030;
const int MG = 200;
const int inf = 1e9;

int d[N];
int b[N], p[N];
bool was[N][MG];
bool useless[N];
vector<pair<int, int>> g[N];

int main() {
   int n, m;
   scanf("%d %d", &n, &m);
   for (int i = 0; i < m; ++i) {
      scanf("%d %d", b + i, p + i);
      if (p[i] < MG) {
         if (was[b[i]][p[i]]) {
            useless[i] = true;
         } else {
            was[b[i]][p[i]] = true;
         }
      }
   }
   for (int i = 0; i < m; ++i) {
      if (useless[i]) continue;
      for (int j = 1; ; ++j) {
         int v = b[i] - j * p[i];
         if (v < 0) break;
         g[b[i]].emplace_back(v, j);
         if (p[i] < MG && was[v][p[i]]) {
            break;
         }
      }
      for (int j = 1; ; ++j) {
         int v = b[i] + j * p[i];
         if (v >= n) break;
         g[b[i]].emplace_back(v, j);
         if (p[i] < MG && was[v][p[i]]) {
            break;
         }
      }
   }
   for (int i = 0; i < n; ++i) {
      d[i] = inf;
   }
   priority_queue<pair<int, int>> q;
   d[b[0]] = 0;
   q.emplace(0, b[0]);
   while (!q.empty()) {
      int du, u;
      tie(du, u) = q.top();
      q.pop();
      du = -du;
      if (d[u] != du) {
         continue;
      }
      for (auto e : g[u]) {
         int v, w;
         tie(v, w) = e;
         if (d[v] > d[u] + w) {
            d[v] = d[u] + w;
            q.emplace(-d[v], v);
         }
      }
   }
   printf("%d\n", (d[b[1]] == inf ? -1 : d[b[1]]));
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &n, &m);
    ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:19:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", b + i, p + i);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 4 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 4 ms 1152 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 3 ms 1024 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 4 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 4 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 2 ms 1024 KB Output is correct
8 Correct 3 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 3 ms 1024 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 4 ms 1152 KB Output is correct
13 Correct 3 ms 1228 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 4 ms 1144 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 4 ms 1408 KB Output is correct
18 Correct 3 ms 1408 KB Output is correct
19 Correct 4 ms 1280 KB Output is correct
20 Correct 4 ms 1536 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 4 ms 1280 KB Output is correct
23 Correct 4 ms 1408 KB Output is correct
24 Correct 5 ms 1536 KB Output is correct
25 Correct 4 ms 1252 KB Output is correct
26 Correct 4 ms 1408 KB Output is correct
27 Correct 4 ms 1280 KB Output is correct
28 Correct 5 ms 1408 KB Output is correct
29 Correct 5 ms 1920 KB Output is correct
30 Correct 4 ms 1368 KB Output is correct
31 Correct 4 ms 1536 KB Output is correct
32 Correct 4 ms 1408 KB Output is correct
33 Correct 3 ms 2560 KB Output is correct
34 Correct 3 ms 2560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 2 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 9 ms 1024 KB Output is correct
13 Correct 3 ms 1024 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 6 ms 1408 KB Output is correct
18 Correct 4 ms 1408 KB Output is correct
19 Correct 4 ms 1280 KB Output is correct
20 Correct 4 ms 1536 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1280 KB Output is correct
23 Correct 4 ms 1408 KB Output is correct
24 Correct 4 ms 1536 KB Output is correct
25 Correct 6 ms 1280 KB Output is correct
26 Correct 7 ms 1408 KB Output is correct
27 Correct 4 ms 1280 KB Output is correct
28 Correct 5 ms 1408 KB Output is correct
29 Correct 5 ms 1920 KB Output is correct
30 Correct 4 ms 1408 KB Output is correct
31 Correct 4 ms 1536 KB Output is correct
32 Correct 4 ms 1408 KB Output is correct
33 Correct 6 ms 2432 KB Output is correct
34 Correct 6 ms 2560 KB Output is correct
35 Correct 13 ms 2944 KB Output is correct
36 Correct 6 ms 1536 KB Output is correct
37 Correct 14 ms 3968 KB Output is correct
38 Correct 18 ms 3840 KB Output is correct
39 Correct 15 ms 3864 KB Output is correct
40 Correct 15 ms 3840 KB Output is correct
41 Correct 16 ms 3812 KB Output is correct
42 Correct 8 ms 1792 KB Output is correct
43 Correct 8 ms 1664 KB Output is correct
44 Correct 8 ms 1920 KB Output is correct
45 Correct 16 ms 6328 KB Output is correct
46 Correct 16 ms 6400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 4 ms 1024 KB Output is correct
8 Correct 4 ms 1024 KB Output is correct
9 Correct 13 ms 1024 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 4 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 4 ms 1152 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 4 ms 1084 KB Output is correct
17 Correct 5 ms 1408 KB Output is correct
18 Correct 4 ms 1408 KB Output is correct
19 Correct 3 ms 1280 KB Output is correct
20 Correct 4 ms 1536 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1280 KB Output is correct
23 Correct 4 ms 1408 KB Output is correct
24 Correct 4 ms 1664 KB Output is correct
25 Correct 4 ms 1280 KB Output is correct
26 Correct 10 ms 1408 KB Output is correct
27 Correct 5 ms 1280 KB Output is correct
28 Correct 4 ms 1408 KB Output is correct
29 Correct 5 ms 1920 KB Output is correct
30 Correct 4 ms 1408 KB Output is correct
31 Correct 4 ms 1536 KB Output is correct
32 Correct 3 ms 1408 KB Output is correct
33 Correct 6 ms 2432 KB Output is correct
34 Correct 6 ms 2560 KB Output is correct
35 Correct 12 ms 2784 KB Output is correct
36 Correct 4 ms 1536 KB Output is correct
37 Correct 12 ms 3968 KB Output is correct
38 Correct 14 ms 3840 KB Output is correct
39 Correct 14 ms 3840 KB Output is correct
40 Correct 15 ms 3832 KB Output is correct
41 Correct 15 ms 3840 KB Output is correct
42 Correct 9 ms 1792 KB Output is correct
43 Correct 8 ms 1792 KB Output is correct
44 Correct 11 ms 2048 KB Output is correct
45 Correct 16 ms 6400 KB Output is correct
46 Correct 16 ms 6528 KB Output is correct
47 Correct 39 ms 13188 KB Output is correct
48 Correct 15 ms 4476 KB Output is correct
49 Correct 13 ms 3456 KB Output is correct
50 Correct 12 ms 3304 KB Output is correct
51 Correct 39 ms 6396 KB Output is correct
52 Correct 38 ms 6932 KB Output is correct
53 Correct 17 ms 3332 KB Output is correct
54 Correct 5 ms 1664 KB Output is correct
55 Correct 7 ms 2172 KB Output is correct
56 Correct 24 ms 8444 KB Output is correct
57 Correct 47 ms 14844 KB Output is correct
58 Correct 12 ms 2684 KB Output is correct
59 Correct 13 ms 3068 KB Output is correct
60 Correct 14 ms 4092 KB Output is correct
61 Correct 13 ms 3068 KB Output is correct
62 Correct 24 ms 6772 KB Output is correct
63 Correct 67 ms 26440 KB Output is correct
64 Correct 78 ms 35184 KB Output is correct
65 Correct 99 ms 47216 KB Output is correct
66 Correct 160 ms 75984 KB Output is correct
67 Correct 158 ms 75676 KB Output is correct