Submission #683915

#TimeUsernameProblemLanguageResultExecution timeMemory
683915speedyArdaJakarta Skyscrapers (APIO15_skyscraper)C++14
22 / 100
1097 ms188104 KiB
#include "bits/stdc++.h" using namespace std; const int MAXN = 3e4+5; vector< set< pair<int, int> > > adj(MAXN); vector< set < int > > doges(MAXN); int dp[MAXN]; map< pair<int, int>, bool > done; map< pair<int, int>, int> max_road; bool visited[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int goal, begin; for(int i = 0; i < m; i++) { pair<int, int> temp; cin >> temp.first >> temp.second; if(i == 1) goal = temp.first; else if(i == 0) begin = temp.first; doges[temp.first].insert(temp.second); } for(int i = 0; i <= n; i++) { dp[i] = 1e9; visited[i] = false; } visited[begin] = false; dp[begin] = 0; set< pair<int, int> > curr; curr.insert({0, begin}); int ans = 1e9; while(!curr.empty()) { pair<int, int> temp = *(curr.begin()); int v = temp.second; int len = temp.first; //cout << v << "\n"; curr.erase(curr.begin()); // if(v == goal) // ans = min(ans, ) for(int temp : doges[v]) { int currNode = v + temp; int cnt = 1; while(currNode < n) { int val = max_road[{v, currNode}]; if(val == 0 || val > cnt) { adj[v].erase({val, currNode}); max_road[{v, currNode}] = cnt; adj[v].insert({cnt, currNode}); } //if(curr == 4) //cout << temp.first << "\n"; cnt++; currNode += temp; } currNode = v - temp; cnt = 1; while(currNode >= 0) { int val = max_road[{v, currNode}]; if(val == 0 || val > cnt) { adj[v].erase({val, currNode}); max_road[{v, currNode}] = cnt; adj[v].insert({cnt, currNode}); } //if(curr == 4) //cout << temp.first << "\n"; cnt++; currNode -= temp; } } for(pair<int, int> e : adj[v]) { //cout << v << " " << e.second << "\n"; if(dp[e.second] > len + e.first) { curr.erase({dp[e.second], e.second}); dp[e.second] = len + e.first; curr.insert({dp[e.second], e.second}); } } adj[v].clear(); //cout << v << "\n"; //dp[v] = 1e9; } ans = dp[goal]; if(ans >= 1e9) ans = -1; cout << ans << "\n"; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:102:9: warning: 'goal' may be used uninitialized in this function [-Wmaybe-uninitialized]
  102 |     ans = dp[goal];
      |     ~~~~^~~~~~~~~~
#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...