Submission #735927

#TimeUsernameProblemLanguageResultExecution timeMemory
735927CutebolJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms1024 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define Ganyu ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0); #define int long long #define endl "\n" #define ff first #define ss second const int N = 3e4 + 5 ; const int inf = 1e9 ; const int mod = 1e9 + 7 ; int n , m , ans = inf ; int p[N] , d[N] ; vector <pair <int , int> > g[N] ; void djikstra( int s ){ set <pair <int , int> > q ; q.insert({0,s}) ; d[s] = 0 ; while ( !q.empty() ){ int v = q.begin()->ss ; // cout << v << endl ; q.erase(q.begin()) ; for ( auto to : g[v] ){ if ( d[to.ff] > d[v]+to.ss ){ q.erase({d[to.ff],to.ff}) ; d[to.ff] = d[v]+to.ss ; q.insert({d[to.ff],to.ff}) ; } } } } void solve(){ cin >> n >> m ; for ( int i = 0 ; i < n ; i ++ ) d[i] = inf ; for ( int i = 0 ; i < m ; i ++ ){ int x , y ; cin >> x >> p[x] ; for ( int j = x+p[x] ; j < n ; j += p[x] ) g[x].push_back({j,(j-x)/p[x]}) ; for ( int j = x-p[x] ; j >= 0 ; j -= p[x] ) g[x].push_back({j,(x-j)/p[x]}) ; } djikstra(0) ; if ( d[1] == inf ) cout << -1 ; else cout << d[1] ; } signed main(){ // fopn("") ; // Ganyu ; int t = 1 ; // cin >> t ; while ( t -- ) solve() ; }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:49:11: warning: unused variable 'y' [-Wunused-variable]
   49 |   int x , y ;
      |           ^
skyscraper.cpp: In function 'void fopn(std::string)':
skyscraper.cpp:8:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:8:72: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"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...