Submission #563563

#TimeUsernameProblemLanguageResultExecution timeMemory
563563myrcellaJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
374 ms112380 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000000007 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} const int maxn = 3e4+10; int n,m; vector <int> power[maxn]; deque <pair<int,pii>> q; bitset <maxn> vis[maxn]; int main() { // freopen("input.txt","r",stdin); std::ios::sync_with_stdio(false);cin.tie(); cin>>n>>m; int des; rep(i,0,m) { int x,y; cin>>x>>y; power[x].pb(y); if (i==0) q.push_back({0,{x,y}}); if (i==1) des=x; } while (!q.empty()) { int d = q.front().fi; int x = q.front().se.fi, y = q.front().se.se; q.pop_front(); if (vis[x][y]==1) continue; // cout<<x<<" "<<y<<endl; vis[x][y] = 1; if (x==des) { cout<<d; return 0; } if (x+y<n and vis[x+y][y]==0) q.push_back({d+1,{x+y,y}}); if (x-y>=0 and vis[x-y][y]==0) q.push_back({d+1,{x-y,y}}); for (auto it:power[x]) { if (vis[x][it]==0) q.push_front({d,{x,it}}); } } cout<<-1; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:3: warning: 'des' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |   if (x==des) {
      |   ^~
#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...