답안 #399603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399603 2021-05-06T08:43:06 Z fedoseevtimofey Cigle (COI21_cigle) C++14
100 / 100
582 ms 129820 KB
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <bitset>
#include <chrono>
 
using namespace std;
 
typedef long long ll;

struct triple {
  int i, l, r, score;
};
 
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];
  vector <ll> pref(n + 1);
  for (int i = 0; i < n; ++i) {
    pref[i + 1] = pref[i] + d[i];
  }
  vector <triple> gs;
  vector <vector <int>> go(n);
  vector <vector <int>> who(n);
  for (int i = 0; i + 1 < n; ++i) {
    int r = 0;
    for (int l = 1; l <= i + 1; ++l) {
      while (r <= n - i - 1 && pref[i + 1] - pref[i + 1 - l] > pref[i + r + 1] - pref[i + 1]) ++r;
      if (pref[i + 1] - pref[i + 1 - l] == pref[i + r + 1] - pref[i + 1] && i + 1 >= l + 1 && (i + 1) + (r + 1) <= n) {
        gs.push_back({i, l, r, (int)go[i].size() + 1});
        //cout << i + 1 << ' ' << l << ' ' << r << ' ' << go[i].size() + 1 << endl;
        int id = (int)gs.size() - 1;
        go[i].push_back(id);
        who[max(0, i - l)].push_back(id);
      }
    }
  }
  vector <int> fen(n);
  vector <int> best((int)gs.size());
  auto modify = [&] (int id, int val) {
    for (; id < n; id |= id + 1) fen[id] = max(fen[id], val);
  };
  auto get = [&] (int r) {
    int res = 0;
    for (; r >= 0; r &= r + 1, --r) {
      res = max(res, fen[r]);
    }
    return res;
  };
  for (int i = 0; i + 1 < n; ++i) {
    for (int id : who[i]) {
      //cout << "get " << gs[id].i - 1 << ' ' << gs[id].score << ' ' << id << endl;
      best[id] = get(gs[id].i - 1) + gs[id].score;
    }
    for (int id : go[i]) {
      //cout << "set " << gs[id].i + gs[id].r << ' ' << best[id] << ' ' << id << endl;
      modify(min(n - 1, gs[id].i + gs[id].r), best[id]);
    }
  } 
  int ans = 0;
  for (auto x : best) ans = max(ans, x);
  cout << ans << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1196 KB Output is correct
2 Correct 4 ms 1828 KB Output is correct
3 Correct 4 ms 1704 KB Output is correct
4 Correct 4 ms 1704 KB Output is correct
5 Correct 5 ms 1704 KB Output is correct
6 Correct 5 ms 1708 KB Output is correct
7 Correct 5 ms 1684 KB Output is correct
8 Correct 5 ms 1708 KB Output is correct
9 Correct 5 ms 1692 KB Output is correct
10 Correct 4 ms 1708 KB Output is correct
11 Correct 5 ms 1724 KB Output is correct
12 Correct 4 ms 1708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 3 ms 1196 KB Output is correct
22 Correct 4 ms 1828 KB Output is correct
23 Correct 4 ms 1704 KB Output is correct
24 Correct 4 ms 1704 KB Output is correct
25 Correct 5 ms 1704 KB Output is correct
26 Correct 5 ms 1708 KB Output is correct
27 Correct 5 ms 1684 KB Output is correct
28 Correct 5 ms 1708 KB Output is correct
29 Correct 5 ms 1692 KB Output is correct
30 Correct 4 ms 1708 KB Output is correct
31 Correct 5 ms 1724 KB Output is correct
32 Correct 4 ms 1708 KB Output is correct
33 Correct 3 ms 1196 KB Output is correct
34 Correct 4 ms 1704 KB Output is correct
35 Correct 5 ms 1708 KB Output is correct
36 Correct 4 ms 1704 KB Output is correct
37 Correct 5 ms 1708 KB Output is correct
38 Correct 5 ms 1708 KB Output is correct
39 Correct 3 ms 716 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 2 ms 332 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 316 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 3 ms 1196 KB Output is correct
22 Correct 4 ms 1828 KB Output is correct
23 Correct 4 ms 1704 KB Output is correct
24 Correct 4 ms 1704 KB Output is correct
25 Correct 5 ms 1704 KB Output is correct
26 Correct 5 ms 1708 KB Output is correct
27 Correct 5 ms 1684 KB Output is correct
28 Correct 5 ms 1708 KB Output is correct
29 Correct 5 ms 1692 KB Output is correct
30 Correct 4 ms 1708 KB Output is correct
31 Correct 5 ms 1724 KB Output is correct
32 Correct 4 ms 1708 KB Output is correct
33 Correct 3 ms 1196 KB Output is correct
34 Correct 4 ms 1704 KB Output is correct
35 Correct 5 ms 1708 KB Output is correct
36 Correct 4 ms 1704 KB Output is correct
37 Correct 5 ms 1708 KB Output is correct
38 Correct 5 ms 1708 KB Output is correct
39 Correct 3 ms 716 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 2 ms 332 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 316 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 2 ms 332 KB Output is correct
50 Correct 520 ms 121904 KB Output is correct
51 Correct 519 ms 119192 KB Output is correct
52 Correct 503 ms 122128 KB Output is correct
53 Correct 530 ms 121632 KB Output is correct
54 Correct 509 ms 122348 KB Output is correct
55 Correct 502 ms 121760 KB Output is correct
56 Correct 582 ms 129812 KB Output is correct
57 Correct 580 ms 129820 KB Output is correct
58 Correct 235 ms 45064 KB Output is correct
59 Correct 112 ms 8360 KB Output is correct
60 Correct 85 ms 736 KB Output is correct
61 Correct 62 ms 1144 KB Output is correct
62 Correct 63 ms 1284 KB Output is correct
63 Correct 52 ms 2428 KB Output is correct
64 Correct 56 ms 2068 KB Output is correct
65 Correct 54 ms 2108 KB Output is correct
66 Correct 57 ms 1564 KB Output is correct
67 Correct 46 ms 2140 KB Output is correct
68 Correct 45 ms 2108 KB Output is correct
69 Correct 51 ms 2516 KB Output is correct
70 Correct 74 ms 1088 KB Output is correct
71 Correct 80 ms 1152 KB Output is correct
72 Correct 73 ms 2232 KB Output is correct