Submission #189086

#TimeUsernameProblemLanguageResultExecution timeMemory
189086NucleistBali Sculptures (APIO15_sculpture)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define ve vector<ll> #define dos pair<ll,ll> #define vedos vector<dos> #define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) struct greateri { template<class T> bool operator()(T const &a, T const &b) const { return a > b; } }; ll n,v; vector<ll>scrapes[2020]; bool vis[2020][30011]; ll power[30011],dist[2020][30011]; int main() { //flash; cin>>n>>v; ll rooto,dest; for (ll i = 0; i < v; ++i) { ll x,y; cin>>x>>power[i]; if(!vis[x][power[i]])scrapes[x].pb(power[i]); vis[x][power[i]]=1; if(!i)rooto=x; else if(i==1)dest=x; } for (ll i = 0; i < n; ++i) { for (ll j = 0; j < v; ++j) { dist[i][j]=INF; } } priority_queue<pair<ll,pair<ll,ll>>,vector<pair<ll,pair<ll,ll>>>,greater<pair<ll,pair<ll,ll>>>>g; for (ll i = 0; i < scrapes[rooto].size(); ++i) { g.push({0,{rooto,scrapes[rooto][i]}}); dist[rooto][scrapes[rooto][i]]=0; } while(!g.empty()) { auto u = g.top(); auto tower = u.second.first; g.pop(); if(dist[tower][u.second.second]<u.first)continue; for (auto k:scrapes[tower]) { ll next = tower+k; ll last = tower-k; if(last>=0 && dist[last][k]>u.first+1) { dist[last][k]=u.first+1; g.push({u.first+1,{last,k}}); } if(next<n && dist[next][k]>u.first+1) { dist[next][k]=u.first+1; g.push({u.first+1,{next,k}}); } } ll next = tower+u.second.second; ll last = tower-u.second.second; if(last>=0 && dist[last][u.second.second]>u.first+1) { dist[last][u.second.second]=u.first+1; g.push({u.first+1,{last,u.second.second}}); } if(next<n && dist[next][u.second.second]>u.first+1) { dist[next][u.second.second]=u.first+1; g.push({u.first+1,{next,u.second.second}}); } } ll ans=INF; //debugs(rooto,dest); for (ll i = 0; i < v; ++i) { ans=min(ans,dist[dest][i]); } if(ans==INF)cout<<-1; else cout<<ans; return 0; } //code the AC sol ! // BS/queue/map

Compilation message (stderr)

sculpture.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
sculpture.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
sculpture.cpp: In function 'int main()':
sculpture.cpp:35:10: warning: unused variable 'y' [-Wunused-variable]
     ll x,y;
          ^
sculpture.cpp:50:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (ll i = 0; i < scrapes[rooto].size(); ++i)
                  ~~^~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:32:6: warning: 'rooto' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ll rooto,dest;
      ^~~~~
sculpture.cpp:32:12: warning: 'dest' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ll rooto,dest;
            ^~~~
#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...