Submission #317776

#TimeUsernameProblemLanguageResultExecution timeMemory
317776Return_0Jakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
946 ms3828 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize ("Ofast") // #pragma GCC optimize ("O2,unroll-loops") // #pragma GCC target ("avx,avx2,fma") using namespace std; using namespace __gnu_pbds; typedef int ll; typedef long double ld; typedef pair <ll, ll> pll; #ifdef LOCAL #define dbg(x) cout<< #x << " : " << x << endl #define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); #else #define dbg(x) 0 #define dbg2(x, j, n) 0 #endif #define SZ(x) ((ll)((x).size())) #define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout); #define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i]; #define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n'); #define kill(x) return cout<< x << endl, 0 #define cl const ll #define fr first #define sc second #define mid ((l + r) / 2) #define All(x) (x).begin(), (x).end() const long long inf = 1e18; cl mod = 1e9 + 7, MOD = 998244353; template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << '(' << a.first << ", " << a.second << ')'; } template <class A> ostream& operator << (ostream& out, const vector<A> &a) { if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']'; } template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>; cl N = 3e4 + 7; ll dis [N], pos [N], p [N]; priority_queue <pll> pq; bool mark [N]; vector <ll> vec [N]; int main () { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); memset(dis, 61, sizeof dis); ll n, m, i, j, k, v; cin>> n >> m; for (i = 0; i < m; i++) { cin>> pos[i] >> p[i]; vec[pos[i]].push_back(p[i]); } dis[pos[0]] = 0; pq.push({0, pos[0]}); while (!pq.empty()) { v = pq.top().sc, pq.pop(); if (mark[v]) continue; mark[v] = true; for (ll p : vec[v]) { for (i = v, j = 0; i < n; i += p, j++) if (dis[v] + j < dis[i]) dis[i] = dis[v] + j, pq.push({-dis[i], i}); for (i = v, j = 0; i >= 0; i -= p, j++) if (dis[v] + j < dis[i]) dis[i] = dis[v] + j, pq.push({-dis[i], i}); } } if (dis[pos[1]] > mod) kill(-1); cout<< dis[pos[1]] << endl; // cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; } /* 5 3 0 2 1 1 4 1 */

Compilation message (stderr)

skyscraper.cpp: In function 'std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)':
skyscraper.cpp:40:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   40 |     if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
      |     ^~
skyscraper.cpp:40:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   40 |     if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
      |                                    ^~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:56:20: warning: unused variable 'k' [-Wunused-variable]
   56 |     ll n, m, i, j, k, v;
      |                    ^
#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...