Submission #31985

#TimeUsernameProblemLanguageResultExecution timeMemory
31985chonkaJakarta Skyscrapers (APIO15_skyscraper)C++98
10 / 100
0 ms2840 KiB
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<queue> using namespace std ; #define MAXN 30007 int n , m ; int st , en ; vector < int > v[ MAXN ] ; int dist[ MAXN ] ; void bfs ( ) { int i , j ; queue < int > q ; q.push ( st ) ; dist[ st ] = 1 ; while ( q.empty ( ) == false ) { int vertex = q.front ( ) ; q.pop ( ) ; int sz = v[ vertex ].size ( ) ; for ( i = sz - 1 ; i >= 0 ; i -- ) { if ( i != ( sz - 1 ) && v[ vertex ][ i ] == v[ vertex ][ i + 1 ] ) { continue ; } int br = 0 ; for ( j = vertex ; j <= n ; j += v[ vertex ][ i ] ) { if ( dist[ j ] == 0 ) { dist[ j ] = dist[ vertex ] + br ; q.push ( j ) ; } if ( j == en ) { return ; } br ++ ; } br = 0 ; for ( j = vertex ; j >= 1 ; j -= v[ vertex ][ i ] ) { if ( dist[ j ] == 0 ) { dist[ j ] = dist[ vertex ] + br ; q.push ( j ) ; } if ( j == en ) { return ; } br ++ ; } } } } void input ( ) { scanf ( "%d%d" , &n , &m ) ; int i ; for ( i = 1 ; i <= m ; i ++ ) { int x, y ; scanf ( "%d%d" , &x , &y ) ; x ++ ; v[ x ].push_back ( y ) ; if ( i == 1 ) { st = x ; } if ( i == 2 ) { en = x ; } } for ( i = 1 ; i <= n ; i ++ ) { sort ( v[ i ].begin ( ) , v[ i ].end ( ) ) ; } } void solve ( ) { bfs ( ) ; printf ( "%d\n" , dist[ en ] - 1 ) ; } int main ( ) { input ( ) ; solve ( ) ; return 0 ; }

Compilation message (stderr)

skyscraper.cpp: In function 'void input()':
skyscraper.cpp:52:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d%d" , &n , &m ) ;
                                ^
skyscraper.cpp:56:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d%d" , &x , &y ) ;
                                    ^
#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...