Submission #31985

# Submission time Handle Problem Language Result Execution time Memory
31985 2017-09-20T11:09:52 Z chonka Jakarta Skyscrapers (APIO15_skyscraper) C++
10 / 100
0 ms 2840 KB
#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

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 time Memory Grader output
1 Correct 0 ms 2840 KB Output is correct
2 Correct 0 ms 2840 KB Output is correct
3 Correct 0 ms 2840 KB Output is correct
4 Correct 0 ms 2840 KB Output is correct
5 Correct 0 ms 2840 KB Output is correct
6 Correct 0 ms 2840 KB Output is correct
7 Correct 0 ms 2840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2840 KB Output is correct
2 Correct 0 ms 2840 KB Output is correct
3 Correct 0 ms 2840 KB Output is correct
4 Correct 0 ms 2840 KB Output is correct
5 Correct 0 ms 2840 KB Output is correct
6 Correct 0 ms 2840 KB Output is correct
7 Correct 0 ms 2840 KB Output is correct
8 Correct 0 ms 2840 KB Output is correct
9 Incorrect 0 ms 2840 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2840 KB Output is correct
2 Correct 0 ms 2840 KB Output is correct
3 Correct 0 ms 2840 KB Output is correct
4 Correct 0 ms 2840 KB Output is correct
5 Correct 0 ms 2840 KB Output is correct
6 Correct 0 ms 2840 KB Output is correct
7 Correct 0 ms 2840 KB Output is correct
8 Correct 0 ms 2840 KB Output is correct
9 Incorrect 0 ms 2840 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2840 KB Output is correct
2 Correct 0 ms 2840 KB Output is correct
3 Correct 0 ms 2840 KB Output is correct
4 Correct 0 ms 2840 KB Output is correct
5 Correct 0 ms 2840 KB Output is correct
6 Correct 0 ms 2840 KB Output is correct
7 Correct 0 ms 2840 KB Output is correct
8 Correct 0 ms 2840 KB Output is correct
9 Incorrect 0 ms 2840 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2840 KB Output is correct
2 Correct 0 ms 2840 KB Output is correct
3 Correct 0 ms 2840 KB Output is correct
4 Correct 0 ms 2840 KB Output is correct
5 Correct 0 ms 2840 KB Output is correct
6 Correct 0 ms 2840 KB Output is correct
7 Correct 0 ms 2840 KB Output is correct
8 Correct 0 ms 2840 KB Output is correct
9 Incorrect 0 ms 2840 KB Output isn't correct
10 Halted 0 ms 0 KB -