Submission #31895

# Submission time Handle Problem Language Result Execution time Memory
31895 2017-09-12T14:40:29 Z chonka Brunhilda’s Birthday (BOI13_brunhilda) C++
41.5873 / 100
123 ms 43196 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std ;

#define MAXN 100007

int n  , m ;
int a[ MAXN ] ;
int b[ MAXN ] ;
int ans[ 100 * MAXN ] ;
int akt[ MAXN ] ;
int lim ;

void input ( ) {
    scanf ( "%d%d" , &n , &m ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
    lim = 1 ;
    int i , j ;
    for ( i = 1 ; i <= 7 ; i ++ ) {
        lim *= 10 ;
    }
    deque < pair < int , int > > q ;
    long long prod = 1 ;
    for ( i = 1 ; i <= n ; i ++ ) {
        prod *= a[ i ] ;
        if ( prod > lim ) { prod = lim + 1 ; }
        q.push_front ( make_pair ( 0 , i ) ) ;
        akt[ i ] = 0 ;
    }
    for ( i = 1 ; i <= lim ; i ++ ) {
        if ( i >= prod ) {
            ans[ i ] = -1 ;
            continue ;
        }
        while ( q.empty ( ) == false ) {
            pair < int , int > p = q.back ( ) ;
            if ( p.first + a[ p.second ] <= i ) {
                q.push_front ( make_pair ( p.first + a[ p.second ] , p.second ) ) ;
                q.pop_back ( ) ;
            }
            else { break ; }
        }
        ans[ i ] = ans[ (q.back()).first ] + 1 ;
        if ( ans[ q.back().first ] == -1 || (q.back()).first == i ) { ans[ i ] = -1 ; }
    }
    while ( m != 0 ) {
        m -- ;
        int x ;
        scanf ( "%d" , &x ) ;
        if ( ans[ x ] != -1 ) {
            printf ( "%d\n" , ans[ x ] ) ;
        }
        else {
            printf ( "oo\n" ) ;
        }
    }

}


int main ( ) {
    input ( ) ;
    solve ( ) ;
    return 0 ;
}

Compilation message

brunhilda.cpp: In function 'void solve()':
brunhilda.cpp:26:13: warning: unused variable 'j' [-Wunused-variable]
     int i , j ;
             ^
brunhilda.cpp: In function 'void input()':
brunhilda.cpp:17:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d%d" , &n , &m ) ;
                                ^
brunhilda.cpp:20:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ i ] ) ;
                                  ^
brunhilda.cpp: In function 'void solve()':
brunhilda.cpp:57:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &x ) ;
                             ^
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 42252 KB Output isn't correct
2 Incorrect 59 ms 42252 KB Output isn't correct
3 Incorrect 6 ms 42252 KB Output isn't correct
4 Incorrect 73 ms 42252 KB Output isn't correct
5 Correct 59 ms 42252 KB Output is correct
6 Incorrect 9 ms 42252 KB Output isn't correct
7 Incorrect 16 ms 42252 KB Output isn't correct
8 Incorrect 13 ms 42252 KB Output isn't correct
9 Incorrect 69 ms 42252 KB Output isn't correct
10 Incorrect 43 ms 42252 KB Output isn't correct
11 Incorrect 53 ms 42252 KB Output isn't correct
12 Correct 59 ms 42252 KB Output is correct
13 Correct 49 ms 42252 KB Output is correct
14 Correct 66 ms 42252 KB Output is correct
15 Incorrect 43 ms 42252 KB Output isn't correct
16 Incorrect 53 ms 42252 KB Output isn't correct
17 Incorrect 56 ms 42252 KB Output isn't correct
18 Incorrect 43 ms 42252 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 42384 KB Output is correct
2 Correct 59 ms 43044 KB Output is correct
3 Incorrect 66 ms 42912 KB Output isn't correct
4 Incorrect 56 ms 42252 KB Output isn't correct
5 Correct 49 ms 42648 KB Output is correct
6 Correct 49 ms 42252 KB Output is correct
7 Correct 43 ms 42384 KB Output is correct
8 Incorrect 49 ms 42252 KB Output isn't correct
9 Correct 66 ms 42912 KB Output is correct
10 Incorrect 46 ms 42912 KB Output isn't correct
11 Incorrect 33 ms 42648 KB Output isn't correct
12 Incorrect 49 ms 42252 KB Output isn't correct
13 Correct 46 ms 42252 KB Output is correct
14 Incorrect 39 ms 42252 KB Output isn't correct
15 Correct 56 ms 42648 KB Output is correct
16 Correct 69 ms 43044 KB Output is correct
17 Incorrect 26 ms 42252 KB Output isn't correct
18 Incorrect 69 ms 43196 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 42648 KB Output is correct
2 Correct 53 ms 42784 KB Output is correct
3 Incorrect 63 ms 42648 KB Output isn't correct
4 Incorrect 99 ms 42252 KB Output isn't correct
5 Correct 103 ms 43188 KB Output is correct
6 Incorrect 123 ms 42384 KB Output isn't correct
7 Correct 79 ms 43196 KB Output is correct
8 Correct 83 ms 42648 KB Output is correct
9 Correct 89 ms 42648 KB Output is correct
10 Incorrect 53 ms 42384 KB Output isn't correct
11 Incorrect 46 ms 42252 KB Output isn't correct
12 Incorrect 56 ms 42384 KB Output isn't correct
13 Incorrect 79 ms 42516 KB Output isn't correct
14 Incorrect 96 ms 42252 KB Output isn't correct
15 Incorrect 53 ms 42252 KB Output isn't correct
16 Incorrect 46 ms 42384 KB Output isn't correct
17 Correct 56 ms 42648 KB Output is correct
18 Correct 69 ms 42784 KB Output is correct
19 Correct 63 ms 42252 KB Output is correct
20 Incorrect 69 ms 42648 KB Output isn't correct
21 Incorrect 73 ms 42252 KB Output isn't correct
22 Correct 113 ms 43196 KB Output is correct
23 Correct 99 ms 42516 KB Output is correct
24 Incorrect 73 ms 42252 KB Output isn't correct
25 Incorrect 106 ms 42252 KB Output isn't correct
26 Incorrect 76 ms 42252 KB Output isn't correct
27 Incorrect 69 ms 43196 KB Output isn't correct
28 Incorrect 53 ms 42252 KB Output isn't correct
29 Correct 113 ms 43196 KB Output is correct
30 Correct 96 ms 42912 KB Output is correct
31 Correct 73 ms 42252 KB Output is correct
32 Incorrect 66 ms 42252 KB Output isn't correct
33 Incorrect 79 ms 42252 KB Output isn't correct
34 Correct 103 ms 43196 KB Output is correct
35 Incorrect 73 ms 42252 KB Output isn't correct
36 Correct 109 ms 43044 KB Output is correct
37 Correct 106 ms 43188 KB Output is correct
38 Incorrect 103 ms 42384 KB Output isn't correct
39 Incorrect 99 ms 42252 KB Output isn't correct
40 Correct 123 ms 42384 KB Output is correct
41 Correct 59 ms 43196 KB Output is correct
42 Incorrect 76 ms 42252 KB Output isn't correct