답안 #653978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653978 2022-10-29T06:51:25 Z pavement Cigle (COI21_cigle) C++17
48 / 100
1000 ms 59588 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
//~ #define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, ans, t[10005], d[5005], p[5005], dp[5005][5005];

const int h = sizeof(int) * 8 - __builtin_clz(5000);

void apply(int p, int value) {
  t[p] += value;
  if (p < N) d[p] += value;
}

void build(int p) {
  while (p > 1) p >>= 1, t[p] = max(t[p<<1], t[p<<1|1]) + d[p];
}

void push(int p) {
  for (int s = h; s > 0; --s) {
    int i = p >> s;
    if (d[i] != 0) {
      apply(i<<1, d[i]);
      apply(i<<1|1, d[i]);
      d[i] = 0;
    }
  }
}

void inc(int l, int r, int value) {
  l += N, r += N;
  int l0 = l, r0 = r;
  for (; l < r; l >>= 1, r >>= 1) {
    if (l&1) apply(l++, value);
    if (r&1) apply(--r, value);
  }
  build(l0);
  build(r0 - 1);
}

int query(int l, int r) {
  l += N, r += N;
  push(l);
  push(r - 1);
  int res = -2e9;
  for (; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = max(res, t[l++]);
    if (r&1) res = max(t[--r], res);
  }
  return res;
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> p[i];
		p[i] += p[i - 1];
	}
	for (int j = N; j >= 1; j--) {
		memset(t, 0, sizeof t);
		memset(d, 0, sizeof d);
		for (int k = j + 1; k <= N; k++) {
			inc(k - 1, k, dp[j + 1][k]);
		}
		int ptr = j + 1;
		for (int i = j; i >= 1; i--) {
			int ans = -1;
			while (ptr <= N && p[ptr] - p[j] < p[j] - p[i - 1]) ptr++;
			if (ptr <= N && p[ptr] - p[j] == p[j] - p[i - 1]) ans = ptr;
			dp[i][j] = query(0, N);
			//~ cout << "DP " << i << ' ' << j << ' ' << root->val << '\n';
			if (ans != -1) {
				inc(ans, N, 1);
				//~ cout << " + " << i << ' ' << ans << '\n';
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		ans = max(ans, dp[1][i]);
	}
	cout << ans << '\n';
}

Compilation message

cigle.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 652 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 720 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 2780 KB Output is correct
2 Correct 19 ms 2900 KB Output is correct
3 Correct 15 ms 2904 KB Output is correct
4 Correct 17 ms 2888 KB Output is correct
5 Correct 17 ms 2832 KB Output is correct
6 Correct 17 ms 2900 KB Output is correct
7 Correct 21 ms 2896 KB Output is correct
8 Correct 17 ms 2856 KB Output is correct
9 Correct 16 ms 2860 KB Output is correct
10 Correct 16 ms 2856 KB Output is correct
11 Correct 15 ms 2892 KB Output is correct
12 Correct 14 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 652 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 720 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 14 ms 2780 KB Output is correct
22 Correct 19 ms 2900 KB Output is correct
23 Correct 15 ms 2904 KB Output is correct
24 Correct 17 ms 2888 KB Output is correct
25 Correct 17 ms 2832 KB Output is correct
26 Correct 17 ms 2900 KB Output is correct
27 Correct 21 ms 2896 KB Output is correct
28 Correct 17 ms 2856 KB Output is correct
29 Correct 16 ms 2860 KB Output is correct
30 Correct 16 ms 2856 KB Output is correct
31 Correct 15 ms 2892 KB Output is correct
32 Correct 14 ms 2900 KB Output is correct
33 Correct 15 ms 2880 KB Output is correct
34 Correct 17 ms 2824 KB Output is correct
35 Correct 15 ms 2908 KB Output is correct
36 Correct 17 ms 2788 KB Output is correct
37 Correct 20 ms 2884 KB Output is correct
38 Correct 17 ms 2812 KB Output is correct
39 Correct 14 ms 2860 KB Output is correct
40 Correct 18 ms 2880 KB Output is correct
41 Correct 14 ms 2900 KB Output is correct
42 Correct 13 ms 2900 KB Output is correct
43 Correct 15 ms 2852 KB Output is correct
44 Correct 13 ms 2900 KB Output is correct
45 Correct 13 ms 2900 KB Output is correct
46 Correct 13 ms 2848 KB Output is correct
47 Correct 13 ms 2900 KB Output is correct
48 Correct 15 ms 2856 KB Output is correct
49 Correct 14 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 652 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 720 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 14 ms 2780 KB Output is correct
22 Correct 19 ms 2900 KB Output is correct
23 Correct 15 ms 2904 KB Output is correct
24 Correct 17 ms 2888 KB Output is correct
25 Correct 17 ms 2832 KB Output is correct
26 Correct 17 ms 2900 KB Output is correct
27 Correct 21 ms 2896 KB Output is correct
28 Correct 17 ms 2856 KB Output is correct
29 Correct 16 ms 2860 KB Output is correct
30 Correct 16 ms 2856 KB Output is correct
31 Correct 15 ms 2892 KB Output is correct
32 Correct 14 ms 2900 KB Output is correct
33 Correct 15 ms 2880 KB Output is correct
34 Correct 17 ms 2824 KB Output is correct
35 Correct 15 ms 2908 KB Output is correct
36 Correct 17 ms 2788 KB Output is correct
37 Correct 20 ms 2884 KB Output is correct
38 Correct 17 ms 2812 KB Output is correct
39 Correct 14 ms 2860 KB Output is correct
40 Correct 18 ms 2880 KB Output is correct
41 Correct 14 ms 2900 KB Output is correct
42 Correct 13 ms 2900 KB Output is correct
43 Correct 15 ms 2852 KB Output is correct
44 Correct 13 ms 2900 KB Output is correct
45 Correct 13 ms 2900 KB Output is correct
46 Correct 13 ms 2848 KB Output is correct
47 Correct 13 ms 2900 KB Output is correct
48 Correct 15 ms 2856 KB Output is correct
49 Correct 14 ms 2900 KB Output is correct
50 Execution timed out 1095 ms 59588 KB Time limit exceeded
51 Halted 0 ms 0 KB -