Submission #634838

#TimeUsernameProblemLanguageResultExecution timeMemory
634838mdn2002Robot (JOI21_ho_t4)C++14
34 / 100
3101 ms59928 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2") #define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; struct edg { long long a , b , c , p , ind; }; struct edgg { long long b , c , p , ind , sum; }; long long n , m , dp [600005] , summ [200005]; vector < edgg > gr [100005]; vector < edg > edgs; int main () { scanf ( "%lld%lld" , &n , &m ); for ( int i = 1 ; i <= n ; i ++ ) { edgs . push_back ( { i , 0 , 0 , 0 , i - 1 } ); } for ( int i = 0 ; i < m ; i ++ ) { long long x , y , c , p; scanf ( "%lld%lld%lld%lld" , &x , &y , &c , &p ); gr [y] . push_back ( { x , c , p , edgs . size () } ); edgs . push_back ( { x , y , c , p , edgs . size () } ); gr [x] . push_back ( { y , c , p , edgs . size () } ); edgs . push_back ( { y , x , c , p , edgs . size () } ); } for ( int i = 1 ; i <= n ; i ++ ) { for ( auto x : gr [i] ) summ [ x . c ] += x . p; for ( int j = 0 ; j < gr [i] . size () ; j ++ ) gr [i][j] . sum = summ [ gr [i][j] . c ]; for ( auto x : gr [i] ) summ [ x . c ] = 0; } for ( int i = 0 ; i <= n + m + m + 1 ; i ++ ) dp [i] = 1e16; dp [0] = 0; priority_queue < pair < long long , int > > q; q . push ( { 0 , 0 } ); long long ans = 1e16; while ( q . size () ) { pair < long long , int > p = q . top (); q . pop (); int ind = p . second; if ( dp [ind] != - p . first ) continue; int x = edgs [ind] . a , last = edgs [ind] . b; if ( x == n ) { ans = min ( ans , dp [ind] ); break; } for ( auto uu : gr [x] ) { long long u = uu . b , c = uu . c , p = uu . p; long long sum = uu . sum; sum -= p; if ( last && edgs [ind] . c == c ) sum -= edgs [ind] . p; int indd = u - 1; if ( dp [ind] + sum < dp [indd] ) { dp [indd] = dp [ind] + sum; q . push ( { - dp [indd] , indd } ); } indd = uu . ind; if ( dp [ind] + p < dp [indd] ) { dp [indd] = dp [ind] + p; q . push ( { - dp [indd] , indd } ); } } } if ( ans == 1e16 ) printf ( "-1" ); else printf ( "%lld" , ans ); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:33:56: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'long long int' [-Wnarrowing]
   33 |         gr [y] . push_back ( { x , c , p , edgs . size () } );
      |                                            ~~~~~~~~~~~~^~
Main.cpp:34:58: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'long long int' [-Wnarrowing]
   34 |         edgs . push_back ( { x , y , c , p , edgs . size () } );
      |                                              ~~~~~~~~~~~~^~
Main.cpp:36:56: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'long long int' [-Wnarrowing]
   36 |         gr [x] . push_back ( { y , c , p , edgs . size () } );
      |                                            ~~~~~~~~~~~~^~
Main.cpp:37:58: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'long long int' [-Wnarrowing]
   37 |         edgs . push_back ( { y , x , c , p , edgs . size () } );
      |                                              ~~~~~~~~~~~~^~
Main.cpp:44:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edgg>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for ( int j = 0 ; j < gr [i] . size () ; j ++ ) gr [i][j] . sum = summ [ gr [i][j] . c ];
      |                           ~~^~~~~~~~~~~~~~~~~~
Main.cpp:22:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf ( "%lld%lld" , &n , &m );
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:31:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf ( "%lld%lld%lld%lld" , &x , &y , &c , &p );
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...