Submission #1134868

#TimeUsernameProblemLanguageResultExecution timeMemory
1134868Roumak77Jakarta Skyscrapers (APIO15_skyscraper)C++20
0 / 100
0 ms328 KiB
#pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize("-Ofast") #include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <vector> #include <limits> #include <cmath> #include <stack> #include <queue> #include <map> #include <math.h> using namespace std; /* * Score : 36/100 * * Subtask 4 (21 points) * Subtask 5 (43 points) */ using ll = int; void solve(){ ll n, m; cin >> n >> m; vector<vector<pair<ll, ll>>> adj(m, vector<pair<ll, ll>>()); vector<pair<ll, ll>> list_n(m, {0, 0}); for(ll i = 0; i < m; i++){ cin >> list_n[i].first; cin >> list_n[i].second; } for(ll i = 0; i < m - 1; i++){ for(ll j = i + 1; j < m; j++){ if(abs(list_n[j].first - list_n[i].first)%list_n[i].second == 0){ adj[i].push_back({j, abs(list_n[j].first - list_n[i].first)/list_n[i].second}); } if(abs(list_n[j].first - list_n[i].first)%list_n[j].second == 0){ adj[j].push_back({i, abs(list_n[j].first - list_n[i].first)/list_n[j].second}); } } } multiset<pair<ll, ll>> mult; vector<ll> vis(m, 1E17); mult.insert({0, 0}); vis[0] = 0; while(!mult.empty()){ auto top = *(mult.begin()); mult.erase(mult.begin()); for(auto node : adj[top.second]){ if(vis[node.first] <= top.first + node.second){ continue; }else{ vis[node.first] = top.first + node.second; mult.insert({top.first + node.second, node.first}); } } } if(vis[1] == 1E17){ cout << -1 << endl; }else{ cout << vis[1]; } } bool single = true; signed main(){ ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); ll t = 1; if(!single) cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:55:23: warning: overflow in conversion from 'double' to 'std::vector<int>::value_type' {aka 'int'} changes value from '1.0e+17' to '2147483647' [-Woverflow]
   55 |     vector<ll> vis(m, 1E17);
      |                       ^~~~
#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...