Submission #735936

#TimeUsernameProblemLanguageResultExecution timeMemory
735936CutebolJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
239 ms262144 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 ; 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(){ int a , b ; 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] ; if (!i) a = x ; if(i==1) b = 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(a) ; if ( d[b] == inf ) cout << -1 ; else cout << d[b] ; } signed main(){ // fopn("") ; // Ganyu ; int t = 1 ; // cin >> t ; while ( t -- ) solve() ; }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:48:11: warning: unused variable 'y' [-Wunused-variable]
   48 |   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);}
      |                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:56:10: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |  if ( d[b] == inf ) cout << -1 ;
      |       ~~~^
skyscraper.cpp:55:10: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |  djikstra(a) ;
      |  ~~~~~~~~^~~
#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...