답안 #284481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284481 2020-08-27T13:17:28 Z AlexLuchianov Hacker (BOI15_hac) C++14
100 / 100
94 ms 21756 KB
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <deque>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 1000000;
ll v[1 + nmax], sum[1 + nmax];

std::deque<std::pair<int, ll>> dq;

void _insert(int k, ll number) {
  while(0 < dq.size() && number <= dq.back().second)
    dq.pop_back();
  dq.push_back({k, number});
}

void _clear(int lim) {
  while(dq.front().first <= lim)
    dq.pop_front();
}

int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);

  int n;
  std::cin >> n;
  for(int i = 1;i <= n; i++)
    std::cin >> v[i];
  int lim = (n + 1) / 2;
  for(int i = 1;i <= n; i++)
    v[n + i] = v[i];
  for(int i = 1;i <= 2 * n; i++)
    sum[i] = sum[i - 1] + v[i];
  
  for(int i = lim;i <= 2 * lim - 1; i++)
    _insert(i, sum[i] - sum[i - lim]);
  ll result = dq.front().second;
  for(int i = 2 * lim; i <= 2 * n; i++) {
    _insert(i, sum[i] - sum[i - lim]);
    _clear(i - lim);
    result = std::max(result, dq.front().second);
  }
  std::cout << result;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 12 ms 3200 KB Output is correct
5 Correct 32 ms 7416 KB Output is correct
6 Correct 36 ms 9344 KB Output is correct
7 Correct 41 ms 11128 KB Output is correct
8 Correct 68 ms 18168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 12 ms 3200 KB Output is correct
36 Correct 32 ms 7416 KB Output is correct
37 Correct 36 ms 9344 KB Output is correct
38 Correct 41 ms 11128 KB Output is correct
39 Correct 68 ms 18168 KB Output is correct
40 Correct 2 ms 768 KB Output is correct
41 Correct 3 ms 1024 KB Output is correct
42 Correct 5 ms 1408 KB Output is correct
43 Correct 29 ms 7552 KB Output is correct
44 Correct 69 ms 18296 KB Output is correct
45 Correct 14 ms 3840 KB Output is correct
46 Correct 42 ms 11128 KB Output is correct
47 Correct 69 ms 18168 KB Output is correct
48 Correct 57 ms 18424 KB Output is correct
49 Correct 94 ms 21756 KB Output is correct
50 Correct 59 ms 21740 KB Output is correct