Submission #740634

# Submission time Handle Problem Language Result Execution time Memory
740634 2023-05-12T22:44:43 Z abczz Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
365 ms 7952 KB
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <vector>
#include <array>
#define ll long long

using namespace std;

map <array<ll, 2>, ll> mp;
unordered_map <ll, ll> mp2;
queue <array<ll, 3> > Q;
vector <bool> dp[30000];
vector <ll> adj[30000];
bool visited[30000];
ll n, m, k, x, B[30000], P[30000], id[30000], cnt;
int main() {
  cin >> n >> m;
  for (int i=0; i<m; ++i) {
    cin >> B[i] >> P[i];
    adj[B[i]].push_back(i);
    k = B[i]%P[i];
    auto itr = mp.find({P[i], k});
    if (itr == mp.end()) {
      for (int j=0; k+j*P[i]<n; ++j) {
        dp[cnt].push_back(0);
      }
      mp[{P[i], k}] = id[i] = cnt++;
    }
    else id[i] = itr->second;
  }
  Q.push({B[0], 0, 0});
  dp[id[0]][B[0]/P[0]] = true;
  while (!Q.empty()) {
    auto [u, z, w] = Q.front();
    Q.pop();
    if (u == B[1]) {
      cout << w << '\n';
      return 0;
    }
    if (u + P[z] < n && !dp[id[z]][u/P[z]+1]) {
      dp[id[z]][u/P[z]+1] = true;
      Q.push({u+P[z], z, w+1});
    }
    if (u - P[z] >= 0 && !dp[id[z]][u/P[z]-1]) {
      dp[id[z]][u/P[z]-1] = true;
      Q.push({u-P[z], z, w+1});
    }
    if (!visited[u]) {
      visited[u] = true;
      for (auto v : adj[u]) {
        dp[id[v]][u/P[v]] = true;
        if (u + P[v] < n && !dp[id[v]][u/P[v]+1]) {
          dp[id[v]][u/P[v]+1] = true;
          Q.push({u+P[v], v, w+1});
        }
        if (u - P[v] >= 0 && !dp[id[v]][u/P[v]-1]) {
          dp[id[v]][u/P[v]-1] = true;
          Q.push({u-P[v], v, w+1});
        }
      }
    }
  }
  cout << "-1\n";
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |     auto [u, z, w] = Q.front();
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2132 KB Output is correct
2 Correct 1 ms 2132 KB Output is correct
3 Correct 1 ms 2132 KB Output is correct
4 Correct 2 ms 2132 KB Output is correct
5 Correct 2 ms 2388 KB Output is correct
6 Correct 1 ms 2192 KB Output is correct
7 Correct 2 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 1 ms 2192 KB Output is correct
3 Correct 1 ms 2132 KB Output is correct
4 Correct 1 ms 2132 KB Output is correct
5 Correct 2 ms 2132 KB Output is correct
6 Correct 2 ms 2132 KB Output is correct
7 Correct 1 ms 2132 KB Output is correct
8 Correct 1 ms 2132 KB Output is correct
9 Correct 1 ms 2184 KB Output is correct
10 Correct 1 ms 2132 KB Output is correct
11 Correct 3 ms 2388 KB Output is correct
12 Correct 2 ms 2192 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 4 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 1 ms 2188 KB Output is correct
3 Correct 2 ms 2132 KB Output is correct
4 Correct 1 ms 2132 KB Output is correct
5 Correct 2 ms 2132 KB Output is correct
6 Correct 2 ms 2188 KB Output is correct
7 Correct 1 ms 2184 KB Output is correct
8 Correct 1 ms 2132 KB Output is correct
9 Correct 1 ms 2132 KB Output is correct
10 Correct 2 ms 2132 KB Output is correct
11 Correct 2 ms 2388 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 3 ms 2516 KB Output is correct
15 Correct 3 ms 2516 KB Output is correct
16 Correct 2 ms 2320 KB Output is correct
17 Correct 3 ms 2388 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2188 KB Output is correct
20 Correct 3 ms 2328 KB Output is correct
21 Correct 2 ms 2260 KB Output is correct
22 Correct 2 ms 2192 KB Output is correct
23 Correct 3 ms 2260 KB Output is correct
24 Correct 4 ms 2460 KB Output is correct
25 Correct 3 ms 2452 KB Output is correct
26 Correct 3 ms 2192 KB Output is correct
27 Correct 3 ms 2200 KB Output is correct
28 Correct 4 ms 2516 KB Output is correct
29 Correct 3 ms 2260 KB Output is correct
30 Correct 2 ms 2132 KB Output is correct
31 Correct 3 ms 2260 KB Output is correct
32 Correct 2 ms 2260 KB Output is correct
33 Correct 6 ms 2516 KB Output is correct
34 Correct 5 ms 2452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2180 KB Output is correct
2 Correct 1 ms 2132 KB Output is correct
3 Correct 1 ms 2132 KB Output is correct
4 Correct 2 ms 2132 KB Output is correct
5 Correct 1 ms 2132 KB Output is correct
6 Correct 2 ms 2184 KB Output is correct
7 Correct 2 ms 2132 KB Output is correct
8 Correct 1 ms 2132 KB Output is correct
9 Correct 2 ms 2132 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 3 ms 2388 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 3 ms 2428 KB Output is correct
15 Correct 3 ms 2516 KB Output is correct
16 Correct 2 ms 2316 KB Output is correct
17 Correct 3 ms 2388 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2196 KB Output is correct
20 Correct 2 ms 2328 KB Output is correct
21 Correct 3 ms 2260 KB Output is correct
22 Correct 2 ms 2260 KB Output is correct
23 Correct 2 ms 2260 KB Output is correct
24 Correct 3 ms 2388 KB Output is correct
25 Correct 3 ms 2452 KB Output is correct
26 Correct 2 ms 2196 KB Output is correct
27 Correct 3 ms 2260 KB Output is correct
28 Correct 4 ms 2516 KB Output is correct
29 Correct 4 ms 2260 KB Output is correct
30 Correct 2 ms 2132 KB Output is correct
31 Correct 3 ms 2260 KB Output is correct
32 Correct 2 ms 2188 KB Output is correct
33 Correct 6 ms 2516 KB Output is correct
34 Correct 5 ms 2452 KB Output is correct
35 Correct 29 ms 6100 KB Output is correct
36 Correct 5 ms 2836 KB Output is correct
37 Correct 25 ms 5072 KB Output is correct
38 Correct 34 ms 6800 KB Output is correct
39 Correct 30 ms 6208 KB Output is correct
40 Correct 31 ms 6228 KB Output is correct
41 Correct 32 ms 6340 KB Output is correct
42 Correct 14 ms 3408 KB Output is correct
43 Correct 14 ms 3480 KB Output is correct
44 Correct 14 ms 3408 KB Output is correct
45 Correct 51 ms 6952 KB Output is correct
46 Correct 41 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 2 ms 2132 KB Output is correct
3 Correct 1 ms 2132 KB Output is correct
4 Correct 1 ms 2184 KB Output is correct
5 Correct 2 ms 2188 KB Output is correct
6 Correct 1 ms 2132 KB Output is correct
7 Correct 2 ms 2192 KB Output is correct
8 Correct 1 ms 2192 KB Output is correct
9 Correct 2 ms 2132 KB Output is correct
10 Correct 2 ms 2132 KB Output is correct
11 Correct 3 ms 2388 KB Output is correct
12 Correct 2 ms 2200 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 3 ms 2516 KB Output is correct
15 Correct 3 ms 2516 KB Output is correct
16 Correct 2 ms 2324 KB Output is correct
17 Correct 4 ms 2452 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2184 KB Output is correct
20 Correct 2 ms 2332 KB Output is correct
21 Correct 3 ms 2260 KB Output is correct
22 Correct 2 ms 2260 KB Output is correct
23 Correct 2 ms 2260 KB Output is correct
24 Correct 3 ms 2388 KB Output is correct
25 Correct 3 ms 2388 KB Output is correct
26 Correct 2 ms 2260 KB Output is correct
27 Correct 3 ms 2388 KB Output is correct
28 Correct 4 ms 2516 KB Output is correct
29 Correct 4 ms 2260 KB Output is correct
30 Correct 3 ms 2188 KB Output is correct
31 Correct 3 ms 2260 KB Output is correct
32 Correct 2 ms 2260 KB Output is correct
33 Correct 6 ms 2432 KB Output is correct
34 Correct 5 ms 2516 KB Output is correct
35 Correct 29 ms 6024 KB Output is correct
36 Correct 7 ms 2840 KB Output is correct
37 Correct 22 ms 5136 KB Output is correct
38 Correct 34 ms 6836 KB Output is correct
39 Correct 31 ms 6220 KB Output is correct
40 Correct 31 ms 6276 KB Output is correct
41 Correct 34 ms 6316 KB Output is correct
42 Correct 14 ms 3476 KB Output is correct
43 Correct 14 ms 3408 KB Output is correct
44 Correct 13 ms 3408 KB Output is correct
45 Correct 49 ms 6984 KB Output is correct
46 Correct 47 ms 6964 KB Output is correct
47 Correct 30 ms 5804 KB Output is correct
48 Correct 26 ms 5492 KB Output is correct
49 Correct 25 ms 5324 KB Output is correct
50 Correct 18 ms 4480 KB Output is correct
51 Correct 38 ms 6840 KB Output is correct
52 Correct 41 ms 6808 KB Output is correct
53 Correct 35 ms 6684 KB Output is correct
54 Correct 2 ms 2132 KB Output is correct
55 Correct 2 ms 2132 KB Output is correct
56 Correct 17 ms 3996 KB Output is correct
57 Correct 6 ms 2392 KB Output is correct
58 Correct 12 ms 3344 KB Output is correct
59 Correct 16 ms 3496 KB Output is correct
60 Correct 15 ms 3408 KB Output is correct
61 Correct 17 ms 3768 KB Output is correct
62 Correct 49 ms 7024 KB Output is correct
63 Correct 132 ms 6700 KB Output is correct
64 Correct 153 ms 6696 KB Output is correct
65 Correct 208 ms 7236 KB Output is correct
66 Correct 365 ms 7952 KB Output is correct
67 Correct 244 ms 7832 KB Output is correct