Submission #695266

#TimeUsernameProblemLanguageResultExecution timeMemory
695266Mr_PhJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
1 ms288 KiB
///Never gonna give you up. #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; typedef long long int lli; typedef unsigned long long ull; using namespace std; using namespace __gnu_pbds; template<class x> using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>; const ll mod=(ll)1e9+7; const ll mod1=998244353; ///the defines :) #define endl '\n' #define vi vector<int> #define vll vector<ll> #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i]; #define all(arr) arr.begin(),arr.end() #define allr(arr) arr.rbegin(),arr.rend() #define sz size() #define int long long ///the end of the defines ;) void bla() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("notsus.txt","w",stdout); #endif } int n,m; vector<vector<pair<int,int>>>adj; void preprocess(){} void solve() { cin>>n>>m; adj.resize(n+1); map<int,int>mp; for(int i=0;i<m;i++) { int a,b; cin>>a>>b; int cnt=0; mp[i]=a; for(int i=a-b;i>=0;i-=b) { cnt++; adj[a].push_back({i,cnt}); } cnt=0; for(int i=a+b;i<n;i+=b) { cnt++; adj[a].push_back({i,cnt}); } } priority_queue<pair<int,int>>q; q.push({mp[0],0}); vector<int>dis; for(int i=0;i<=n+3;i++)dis.push_back(1e9); dis[mp[0]]=0; bool vs[n+5]={false}; vs[mp[0]]=true; while(q.sz) { int node=q.top().second,cost=q.top().first; q.pop(); vs[node]=false; for(auto i:adj[node]) { if(dis[node]+i.second<dis[i.first]) { dis[i.first]=dis[node]+i.second; if(!vs[i.first]) q.push({dis[i.first], i.first}); vs[i.first] = true; } } } if(dis[mp[1]]==1e9)cout<<-1<<endl; else cout<<dis[mp[1]]<<endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); preprocess(); //bla(); int t=1; //cin>>t; while(t--) solve(); }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:67:30: warning: unused variable 'cost' [-Wunused-variable]
   67 |      int node=q.top().second,cost=q.top().first;
      |                              ^~~~
skyscraper.cpp: In function 'void bla()':
skyscraper.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("notsus.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...