Submission #699250

#TimeUsernameProblemLanguageResultExecution timeMemory
699250nguyentunglamJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1089 ms86852 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 3e4 + 10, M = 8e6 + 10; unordered_map<int, int> dd; vector<int> lst[N]; int d[M]; int cnt; bool mark[N]; int id(int x, int y) { int code = x * (3e4 + 1) + y; if (!dd[code]) dd[code] = ++cnt; return dd[code]; } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n, m; cin >> n >> m; pair<int, int> st, ed; for(int i = 0; i < m; i++) { int b, p; cin >> b >> p; lst[b].push_back(p); if (i == 0) st = make_pair(b, p); if (i == 1) ed = make_pair(b, p); } deque<pair<int, int> > dq; d[id(st.fi, st.se)] = 1; dq.push_back(st); while (!dq.empty()) { auto [pos, jump] = dq.front(); dq.pop_front(); int cur = id(pos, jump); if (!mark[pos]) { for(auto &j : lst[pos]) { int code = id(pos, j); if (!d[code]) d[code] = d[cur], dq.push_front({pos, j}); } mark[pos] = 1; } if (pos + jump < n) { int code = id(pos + jump, jump); if (!d[code]) d[code] = d[cur] + 1, dq.push_back({pos + jump, jump}); } if (pos - jump >= 0) { int code = id(pos - jump, jump); if (!d[code]) d[code] = d[cur] + 1, dq.push_back({pos - jump, jump}); } } cout << d[id(ed.fi, ed.se)] - 1; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:23:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:26:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:27:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...