제출 #745315

#제출 시각아이디문제언어결과실행 시간메모리
745315IBoryJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
171 ms120200 KiB
#include <bits/stdc++.h> #define pii pair<int, int> using namespace std; const int MAX = 999999; unordered_map<int, int> mv[33333]; vector<int> G[MAX]; int D[MAX]; int main() { ios::sync_with_stdio(0); cin.tie(0); int N, M, S, E; cin >> N >> M; map<pii, vector<int>> make; for (int i = 0; i < M; ++i) { int b, p; cin >> b >> p; if (i == 0) S = b; if (i == 1) E = b; make[{p, b % p}].push_back(b); } int node = N; for (auto& [q, v] : make) { auto [p, i] = q; vector<int> fr; for (int j = i; j < N; j += p) fr.push_back(j); int base = -1; for (int n = 0; n < fr.size(); ++n) { G[node].push_back(fr[n]); if (base != -1) G[base].push_back(node); base = node++; } base = -1; for (int n = fr.size() - 1; n >= 0; --n) { G[node].push_back(fr[n]); if (base != -1) G[base].push_back(node); base = node++; } for (int s : v) { int n = (s - i) / p; if (n) G[s].push_back(fr[n - 1]); if (n + 1 < fr.size()) G[s].push_back(fr[n + 1]); if (1 < n) G[s].push_back(node - (n - 1)); if (n + 2 < fr.size()) G[s].push_back(node - 2 * fr.size() + n + 2); } } memset(D, 0x3f, sizeof(D)); D[S] = 0; queue<int> Q; Q.push(S); while (!Q.empty()) { int cur = Q.front(); Q.pop(); for (int next : G[cur]) { if (D[next] < 1e9) continue; D[next] = D[cur] + 1; Q.push(next); } } cout << (D[E] > 1E9 ? -1 : D[E]); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:24:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |  for (auto& [q, v] : make) {
      |             ^
skyscraper.cpp:25:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |   auto [p, i] = q;
      |        ^
skyscraper.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int n = 0; n < fr.size(); ++n) {
      |                   ~~^~~~~~~~~~~
skyscraper.cpp:43:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |    if (n + 1 < fr.size()) G[s].push_back(fr[n + 1]);
      |        ~~~~~~^~~~~~~~~~~
skyscraper.cpp:45:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    if (n + 2 < fr.size()) G[s].push_back(node - 2 * fr.size() + n + 2);
      |        ~~~~~~^~~~~~~~~~~
skyscraper.cpp:62:14: warning: 'E' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |  cout << (D[E] > 1E9 ? -1 : D[E]);
      |           ~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...