Submission #854722

# Submission time Handle Problem Language Result Execution time Memory
854722 2023-09-28T15:47:22 Z QuangBui Cigle (COI21_cigle) C++14
48 / 100
1000 ms 10172 KB
// QuangBuiCP
#ifndef LOCAL
#pragma GCC optimize(3)
#pragma GCC target("avx2")
#endif // LOCAL
#include "bits/stdc++.h"
using namespace std;

#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()

const int N = 5005;

int n;
int a[N];
int pref[N];
int dp[N][N];

int Brute() {
  int ret = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    int cnt = 0;
    set<int> prv, cur;
    int pos = 0, layer = 0;
    bool no = false;
    for (int i = 1; i < n; ++i) {
      int x1 = 0, x2 = 0;
      if (mask >> i & 1) {
        x1 = 1;
      }
      if (mask >> (i - 1) & 1) {
        x2 = 1;
      }
      if (x1 && x2) {
        no = true;
        break;
      }
    }
    if (no) {
      continue;
    }
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        layer++;
        prv = cur;
        cur.clear();
      }
      int sign = 1;
      if (layer % 2) {
        sign *= -1;
      }
      pos += sign * a[i + 1];
      if (prv.count(pos) && i != n - 1 && !(mask >> (i + 1) & 1)) {
        cnt++;
      }
      cur.insert(pos);
    }
    ret = max(ret, cnt);
  }
  return ret;
}

signed main() {
#ifndef LOCAL
  cin.tie(nullptr)->sync_with_stdio(false);
#endif // LOCAL

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
//  if (n <= 20) {
//    cout << Brute() << '\n';
//    return 0;
//  }
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      int s = 0, sr = 0;
      int pos = l;
      int cnt = 0;
      for (int i = l - 1; i >= 1; --i) {
        s += a[i];
        while (pos < r && s > sr) {
          sr += a[pos++];
        }
        dp[l][r] = max(dp[l][r], dp[i][l - 1] + cnt);
        if (s == sr) {
          cnt++;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, dp[i][n]);
  }
  cout << ans << '\n';

#ifdef LOCAL
  cerr << '\n' << clock() << "ms.";
#endif // LOCAL
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 668 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2900 KB Output is correct
2 Correct 37 ms 2896 KB Output is correct
3 Correct 37 ms 2900 KB Output is correct
4 Correct 42 ms 2900 KB Output is correct
5 Correct 38 ms 2896 KB Output is correct
6 Correct 40 ms 2896 KB Output is correct
7 Correct 41 ms 2868 KB Output is correct
8 Correct 40 ms 3148 KB Output is correct
9 Correct 41 ms 2964 KB Output is correct
10 Correct 43 ms 2900 KB Output is correct
11 Correct 39 ms 2900 KB Output is correct
12 Correct 38 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 668 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 36 ms 2900 KB Output is correct
22 Correct 37 ms 2896 KB Output is correct
23 Correct 37 ms 2900 KB Output is correct
24 Correct 42 ms 2900 KB Output is correct
25 Correct 38 ms 2896 KB Output is correct
26 Correct 40 ms 2896 KB Output is correct
27 Correct 41 ms 2868 KB Output is correct
28 Correct 40 ms 3148 KB Output is correct
29 Correct 41 ms 2964 KB Output is correct
30 Correct 43 ms 2900 KB Output is correct
31 Correct 39 ms 2900 KB Output is correct
32 Correct 38 ms 2900 KB Output is correct
33 Correct 36 ms 2900 KB Output is correct
34 Correct 39 ms 2868 KB Output is correct
35 Correct 37 ms 2896 KB Output is correct
36 Correct 39 ms 2908 KB Output is correct
37 Correct 40 ms 2744 KB Output is correct
38 Correct 40 ms 2900 KB Output is correct
39 Correct 42 ms 2900 KB Output is correct
40 Correct 42 ms 2896 KB Output is correct
41 Correct 40 ms 2792 KB Output is correct
42 Correct 41 ms 2896 KB Output is correct
43 Correct 38 ms 2748 KB Output is correct
44 Correct 41 ms 2900 KB Output is correct
45 Correct 39 ms 2900 KB Output is correct
46 Correct 40 ms 2900 KB Output is correct
47 Correct 41 ms 2944 KB Output is correct
48 Correct 38 ms 2844 KB Output is correct
49 Correct 39 ms 2704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 668 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 36 ms 2900 KB Output is correct
22 Correct 37 ms 2896 KB Output is correct
23 Correct 37 ms 2900 KB Output is correct
24 Correct 42 ms 2900 KB Output is correct
25 Correct 38 ms 2896 KB Output is correct
26 Correct 40 ms 2896 KB Output is correct
27 Correct 41 ms 2868 KB Output is correct
28 Correct 40 ms 3148 KB Output is correct
29 Correct 41 ms 2964 KB Output is correct
30 Correct 43 ms 2900 KB Output is correct
31 Correct 39 ms 2900 KB Output is correct
32 Correct 38 ms 2900 KB Output is correct
33 Correct 36 ms 2900 KB Output is correct
34 Correct 39 ms 2868 KB Output is correct
35 Correct 37 ms 2896 KB Output is correct
36 Correct 39 ms 2908 KB Output is correct
37 Correct 40 ms 2744 KB Output is correct
38 Correct 40 ms 2900 KB Output is correct
39 Correct 42 ms 2900 KB Output is correct
40 Correct 42 ms 2896 KB Output is correct
41 Correct 40 ms 2792 KB Output is correct
42 Correct 41 ms 2896 KB Output is correct
43 Correct 38 ms 2748 KB Output is correct
44 Correct 41 ms 2900 KB Output is correct
45 Correct 39 ms 2900 KB Output is correct
46 Correct 40 ms 2900 KB Output is correct
47 Correct 41 ms 2944 KB Output is correct
48 Correct 38 ms 2844 KB Output is correct
49 Correct 39 ms 2704 KB Output is correct
50 Execution timed out 1029 ms 10172 KB Time limit exceeded
51 Halted 0 ms 0 KB -