Submission #99523

#TimeUsernameProblemLanguageResultExecution timeMemory
99523ae04071Jakarta Skyscrapers (APIO15_skyscraper)C++11
57 / 100
1069 ms32632 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; using pii=pair<int,int>; int n,m; vector<int> arr[30000]; queue<pair<pii,int>> que; set<pii> vis; inline int abs(int a) {return a<0 ? -a : a;} void push_val(int a,int b,int c) { if(a+b<0 || a+b>=n) return; pii idx = pii(a+b, abs(b)); if(vis.find(idx)!=vis.end()) return; vis.insert(idx); que.push({idx,c}); } int main() { int ei; scanf("%d%d",&n,&m); for(int i=0,a,b;i<m;i++) { scanf("%d%d",&a,&b); arr[a].push_back(b); if(i==0) { vis.insert({a,0}); que.push({{a,0},0}); } else if(i==1) { ei = a; } } while(!que.empty()) { int cost=que.front().se, pos=que.front().fi.fi, pv=que.front().fi.se; que.pop(); if(pos == ei) { printf("%d\n",cost); return 0; } while(!arr[pos].empty()) { int pp=arr[pos].back(); arr[pos].pop_back(); push_val(pos,pp,cost+1); push_val(pos,-pp,cost+1); } push_val(pos,pv,cost+1); push_val(pos,-pv,cost+1); } puts("-1"); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:38:9: warning: 'ei' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(pos == ei) {
         ^~
#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...