제출 #956044

#제출 시각아이디문제언어결과실행 시간메모리
956044NeltJakarta Skyscrapers (APIO15_skyscraper)C++17
10 / 100
1 ms600 KiB
#include <bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; void solve() { ll n, m; cin >> n >> m; ll b[m], p[m]; vector<ll> eq[n]; for (ll i = 0; i < m; i++) cin >> b[i] >> p[i], eq[b[i]].push_back(i); vector<ll> g[m]; for (ll i = 0; i < n; i++) for (ll j = 1; j < eq[i].size(); j++) g[eq[i][j]].push_back(eq[i][j - 1]), g[eq[i][j - 1]].push_back(eq[i][j]); map<ll, ll> dist[m]; dist[0][b[0]] = 0; deque<pair<ll, ll>> q; q.push_front(make_pair(0, b[0])); while (!q.empty()) { auto [i, j] = q.front(); q.pop_front(); if (j - p[i] >= 0 and (!dist[i].count(j - p[i]) or dist[i][j - p[i]] > dist[i][j] + 1)) dist[i][j - p[i]] = dist[i][j] + 1, q.push_back(make_pair(i, j - p[i])); if (j + p[i] < n and (!dist[i].count(j + p[i]) or dist[i][j + p[i]] > dist[i][j] + 1)) dist[i][j + p[i]] = dist[i][j] + 1, q.push_back(make_pair(i, j + p[i])); if (!eq[j].empty()) if (!dist[eq[j][0]].count(j) or dist[eq[j][0]][j] > dist[i][j]) dist[eq[j][0]][j] = dist[i][j], q.push_front(make_pair(eq[j][0], j)); for (ll k : g[i]) if (!dist[k].count(j) or dist[k][j] > dist[i][j]) dist[k][j] = dist[i][j], q.push_front(make_pair(k, j)); } ll best = 1e18; for (auto i : dist[1]) best = min(best, i.second); if (best == 1e18) best = -1; cout << best << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); ll t = 1; // precomp(); // cin >> t; for (ll i = 1; i <= t; i++) solve(); cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n"; }

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

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:16:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         for (ll j = 1; j < eq[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~~
#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...