Submission #399343

# Submission time Handle Problem Language Result Execution time Memory
399343 2021-05-05T15:32:33 Z model_code Cigle (COI21_cigle) C++17
100 / 100
352 ms 67420 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define pb push_back
#define fi first
#define se second
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define TRACE(x) cerr << #x << "  " << x << endl
template<typename T1, typename T2>inline void minaj(T1 &x, T2 y) { x = (x > y ? y: x);}
template<typename T1, typename T2>inline void maxaj(T1 &x, T2 y) { x = (x < y ? y: x);}

typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;
int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 5005;

int a[MAXN];
int dp[MAXN][MAXN];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);

  int n; cin >> n;

  REP(i, n) {
    cin >> a[i];
  }

  REP(l, n) {
    vector<int> prijelazi;
    REP(x, l) {
      prijelazi.push_back(dp[x][l - 1]);
    }
    reverse(prijelazi.begin(), prijelazi.end());
    prijelazi.push_back(-MAXN);
    for (int i = prijelazi.size() - 2; i >= 0; --i) {
      maxaj(prijelazi[i], prijelazi[i + 1]);
    }

    int delta = 0;
    int best = 0;
    int up = 0, down = 0;

    int i = l - 1, j = l;

    do {
      int du = -1;
      int dd = -1;

      if (i >= 0) {
        du = up + a[i];
      }
      if (j < n) {
        dd = down + a[j];
      }

      if (du == -1) {
        dp[l][j] = best;
        down += a[j];
        j ++;
        continue;
      }
      if (dd == -1) {
        break;
      }
      if (dd < du) {
        dp[l][j] = max(best, delta + prijelazi[l-i-1]);
        down += a[j];
        j ++;
      }
      else if (du < dd) {
        if (i) maxaj(best, dp[i-1][l-1] + delta);
        up += a[i];
        i --;
      }
      else {
        dp[l][j] = max(best, delta + prijelazi[l-i-1]);
        delta ++;
        down += a[j];
        j ++;
      }
    } while (j < n);
  }

  int sol = 0;
  REP(i, n) {
    maxaj(sol, dp[i][n-1]);
  }

  cout << sol << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2764 KB Output is correct
2 Correct 3 ms 2764 KB Output is correct
3 Correct 3 ms 2764 KB Output is correct
4 Correct 3 ms 2764 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 4 ms 2764 KB Output is correct
7 Correct 4 ms 2764 KB Output is correct
8 Correct 4 ms 2768 KB Output is correct
9 Correct 4 ms 2764 KB Output is correct
10 Correct 3 ms 2768 KB Output is correct
11 Correct 3 ms 2872 KB Output is correct
12 Correct 3 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 3 ms 2764 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 3 ms 2764 KB Output is correct
24 Correct 3 ms 2764 KB Output is correct
25 Correct 3 ms 2764 KB Output is correct
26 Correct 4 ms 2764 KB Output is correct
27 Correct 4 ms 2764 KB Output is correct
28 Correct 4 ms 2768 KB Output is correct
29 Correct 4 ms 2764 KB Output is correct
30 Correct 3 ms 2768 KB Output is correct
31 Correct 3 ms 2872 KB Output is correct
32 Correct 3 ms 2764 KB Output is correct
33 Correct 3 ms 2764 KB Output is correct
34 Correct 3 ms 2764 KB Output is correct
35 Correct 3 ms 2764 KB Output is correct
36 Correct 4 ms 2764 KB Output is correct
37 Correct 4 ms 2764 KB Output is correct
38 Correct 4 ms 2764 KB Output is correct
39 Correct 4 ms 2764 KB Output is correct
40 Correct 4 ms 2764 KB Output is correct
41 Correct 4 ms 2768 KB Output is correct
42 Correct 4 ms 2764 KB Output is correct
43 Correct 3 ms 2764 KB Output is correct
44 Correct 4 ms 2764 KB Output is correct
45 Correct 3 ms 2764 KB Output is correct
46 Correct 4 ms 2764 KB Output is correct
47 Correct 4 ms 2764 KB Output is correct
48 Correct 4 ms 2764 KB Output is correct
49 Correct 4 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 3 ms 2764 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 3 ms 2764 KB Output is correct
24 Correct 3 ms 2764 KB Output is correct
25 Correct 3 ms 2764 KB Output is correct
26 Correct 4 ms 2764 KB Output is correct
27 Correct 4 ms 2764 KB Output is correct
28 Correct 4 ms 2768 KB Output is correct
29 Correct 4 ms 2764 KB Output is correct
30 Correct 3 ms 2768 KB Output is correct
31 Correct 3 ms 2872 KB Output is correct
32 Correct 3 ms 2764 KB Output is correct
33 Correct 3 ms 2764 KB Output is correct
34 Correct 3 ms 2764 KB Output is correct
35 Correct 3 ms 2764 KB Output is correct
36 Correct 4 ms 2764 KB Output is correct
37 Correct 4 ms 2764 KB Output is correct
38 Correct 4 ms 2764 KB Output is correct
39 Correct 4 ms 2764 KB Output is correct
40 Correct 4 ms 2764 KB Output is correct
41 Correct 4 ms 2768 KB Output is correct
42 Correct 4 ms 2764 KB Output is correct
43 Correct 3 ms 2764 KB Output is correct
44 Correct 4 ms 2764 KB Output is correct
45 Correct 3 ms 2764 KB Output is correct
46 Correct 4 ms 2764 KB Output is correct
47 Correct 4 ms 2764 KB Output is correct
48 Correct 4 ms 2764 KB Output is correct
49 Correct 4 ms 2764 KB Output is correct
50 Correct 352 ms 67312 KB Output is correct
51 Correct 345 ms 67340 KB Output is correct
52 Correct 326 ms 67308 KB Output is correct
53 Correct 333 ms 67324 KB Output is correct
54 Correct 328 ms 67420 KB Output is correct
55 Correct 324 ms 67324 KB Output is correct
56 Correct 346 ms 67288 KB Output is correct
57 Correct 342 ms 67292 KB Output is correct
58 Correct 347 ms 67236 KB Output is correct
59 Correct 337 ms 67224 KB Output is correct
60 Correct 340 ms 67280 KB Output is correct
61 Correct 324 ms 67268 KB Output is correct
62 Correct 342 ms 67300 KB Output is correct
63 Correct 319 ms 67280 KB Output is correct
64 Correct 329 ms 67268 KB Output is correct
65 Correct 320 ms 67396 KB Output is correct
66 Correct 327 ms 67244 KB Output is correct
67 Correct 328 ms 67324 KB Output is correct
68 Correct 324 ms 67288 KB Output is correct
69 Correct 329 ms 67268 KB Output is correct
70 Correct 326 ms 67308 KB Output is correct
71 Correct 350 ms 67324 KB Output is correct
72 Correct 331 ms 67312 KB Output is correct