답안 #32018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
32018 2017-09-22T12:19:26 Z chonka Hacker (BOI15_hac) C++
100 / 100
99 ms 32368 KB
#include<iostream>
#include<stdio.h>
#include<queue>
using namespace std ;

#define MAXN 500007

int n ;
int a[ 3 * MAXN ] ;
long long pref[ 3 * MAXN ] ;

long long val[ 3 * MAXN ] ;

int len ;

void input ( ) {
    scanf ( "%d" , &n ) ;
    len = ( n / 2 ) + ( n % 2 ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
        a[ n + i ] = a[ i ] ;
        a[ 2 * n + i ] = a[ i ] ;
    }
    for ( i = 1 ; i <= 3 * n ; i ++ ) {
        pref[ i ] = ( pref[ i - 1 ] + a[ i ] ) ;
    }
    for ( i = 1 ; i + len - 1 <= 3 * n ; i ++ ) {
        val[ i ] = pref[ i + len - 1 ] - pref[ i - 1 ] ;
    }
}

void solve ( ) {
    int i ;
    deque < int > q ;
    long long ans = 0 ;
    for ( i = 1 ; i <= 3 * n ; i ++ ) {
        while ( q.empty ( ) == false && val[ q.back ( ) ] >= val[ i ] ) {
            q.pop_back ( ) ;
        }
        q.push_back ( i ) ;
        while ( q.empty ( ) == false && q.front ( ) + len - 1 < i ) {
            q.pop_front ( ) ;
        }
        if ( i > n && i <= 2 * n ) {
            ans = max ( ans , val[ q.front ( ) ] ) ;
        }
    }
    printf ( "%lld\n" , ans ) ;
}

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

Compilation message

hac.cpp: In function 'void input()':
hac.cpp:17:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d" , &n ) ;
                         ^
hac.cpp:21:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ i ] ) ;
                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 31312 KB Output is correct
2 Correct 0 ms 31312 KB Output is correct
3 Correct 0 ms 31312 KB Output is correct
4 Correct 0 ms 31312 KB Output is correct
5 Correct 0 ms 31312 KB Output is correct
6 Correct 0 ms 31312 KB Output is correct
7 Correct 0 ms 31312 KB Output is correct
8 Correct 0 ms 31312 KB Output is correct
9 Correct 0 ms 31312 KB Output is correct
10 Correct 0 ms 31312 KB Output is correct
11 Correct 0 ms 31312 KB Output is correct
12 Correct 0 ms 31312 KB Output is correct
13 Correct 0 ms 31312 KB Output is correct
14 Correct 0 ms 31312 KB Output is correct
15 Correct 0 ms 31312 KB Output is correct
16 Correct 0 ms 31312 KB Output is correct
17 Correct 0 ms 31312 KB Output is correct
18 Correct 0 ms 31312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 31312 KB Output is correct
2 Correct 0 ms 31312 KB Output is correct
3 Correct 0 ms 31312 KB Output is correct
4 Correct 0 ms 31312 KB Output is correct
5 Correct 0 ms 31312 KB Output is correct
6 Correct 0 ms 31312 KB Output is correct
7 Correct 0 ms 31312 KB Output is correct
8 Correct 0 ms 31312 KB Output is correct
9 Correct 0 ms 31312 KB Output is correct
10 Correct 0 ms 31312 KB Output is correct
11 Correct 0 ms 31312 KB Output is correct
12 Correct 0 ms 31312 KB Output is correct
13 Correct 0 ms 31312 KB Output is correct
14 Correct 0 ms 31312 KB Output is correct
15 Correct 0 ms 31312 KB Output is correct
16 Correct 0 ms 31312 KB Output is correct
17 Correct 0 ms 31312 KB Output is correct
18 Correct 0 ms 31312 KB Output is correct
19 Correct 0 ms 31312 KB Output is correct
20 Correct 0 ms 31312 KB Output is correct
21 Correct 0 ms 31312 KB Output is correct
22 Correct 0 ms 31312 KB Output is correct
23 Correct 0 ms 31312 KB Output is correct
24 Correct 0 ms 31312 KB Output is correct
25 Correct 0 ms 31312 KB Output is correct
26 Correct 0 ms 31312 KB Output is correct
27 Correct 0 ms 31312 KB Output is correct
28 Correct 0 ms 31312 KB Output is correct
29 Correct 0 ms 31312 KB Output is correct
30 Correct 0 ms 31312 KB Output is correct
31 Correct 0 ms 31312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 31312 KB Output is correct
2 Correct 0 ms 31312 KB Output is correct
3 Correct 0 ms 31312 KB Output is correct
4 Correct 13 ms 31312 KB Output is correct
5 Correct 26 ms 31312 KB Output is correct
6 Correct 53 ms 31312 KB Output is correct
7 Correct 66 ms 31312 KB Output is correct
8 Correct 99 ms 31312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 31312 KB Output is correct
2 Correct 0 ms 31312 KB Output is correct
3 Correct 0 ms 31312 KB Output is correct
4 Correct 0 ms 31312 KB Output is correct
5 Correct 0 ms 31312 KB Output is correct
6 Correct 0 ms 31312 KB Output is correct
7 Correct 0 ms 31312 KB Output is correct
8 Correct 0 ms 31312 KB Output is correct
9 Correct 0 ms 31312 KB Output is correct
10 Correct 0 ms 31312 KB Output is correct
11 Correct 0 ms 31312 KB Output is correct
12 Correct 0 ms 31312 KB Output is correct
13 Correct 0 ms 31312 KB Output is correct
14 Correct 0 ms 31312 KB Output is correct
15 Correct 0 ms 31312 KB Output is correct
16 Correct 0 ms 31312 KB Output is correct
17 Correct 0 ms 31312 KB Output is correct
18 Correct 0 ms 31312 KB Output is correct
19 Correct 0 ms 31312 KB Output is correct
20 Correct 0 ms 31312 KB Output is correct
21 Correct 0 ms 31312 KB Output is correct
22 Correct 0 ms 31312 KB Output is correct
23 Correct 0 ms 31312 KB Output is correct
24 Correct 0 ms 31312 KB Output is correct
25 Correct 0 ms 31312 KB Output is correct
26 Correct 0 ms 31312 KB Output is correct
27 Correct 0 ms 31312 KB Output is correct
28 Correct 0 ms 31312 KB Output is correct
29 Correct 0 ms 31312 KB Output is correct
30 Correct 0 ms 31312 KB Output is correct
31 Correct 0 ms 31312 KB Output is correct
32 Correct 0 ms 31312 KB Output is correct
33 Correct 0 ms 31312 KB Output is correct
34 Correct 0 ms 31312 KB Output is correct
35 Correct 13 ms 31312 KB Output is correct
36 Correct 26 ms 31312 KB Output is correct
37 Correct 53 ms 31312 KB Output is correct
38 Correct 66 ms 31312 KB Output is correct
39 Correct 99 ms 31312 KB Output is correct
40 Correct 0 ms 31312 KB Output is correct
41 Correct 3 ms 31312 KB Output is correct
42 Correct 6 ms 31312 KB Output is correct
43 Correct 43 ms 31312 KB Output is correct
44 Correct 89 ms 31312 KB Output is correct
45 Correct 16 ms 31312 KB Output is correct
46 Correct 56 ms 31312 KB Output is correct
47 Correct 93 ms 31312 KB Output is correct
48 Correct 73 ms 31312 KB Output is correct
49 Correct 83 ms 32368 KB Output is correct
50 Correct 93 ms 32368 KB Output is correct