Submission #475572

# Submission time Handle Problem Language Result Execution time Memory
475572 2021-09-23T03:58:23 Z flashmt Tortoise (CEOI21_tortoise) C++17
48 / 100
3000 ms 143712 KB
#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 30;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  vector<int> l(n), r(n);
  for (int i = 0, last = -oo; i < n; i++)
    if (a[i] < 0) last = i;
    else l[i] = last;
  for (int i = n - 1, last = oo; i >= 0; i--)
    if (a[i] < 0) last = i;
    else r[i] = last;

  if (n > 5000)
    return 0;

  int mx = (n * 3 + 1) / 2;
  vector<vector<int>> f(n, vector<int>(mx + 1, oo));
  for (int i = 0; i < n; i++)
    if (a[i] > 0)
    {
      f[i][0] = i;
      for (int ii = 0; ii < i; ii++)
        if (a[ii] > 0)
          for (int j = 0; j <= mx; j++)
            if (f[ii][j] <= ii * 2)
            {
              f[i][j] = min(f[i][j], f[ii][j] + i - ii);
              if (j < mx)
              {
                if (r[ii] < n)
                  f[i][j + 1] = min(f[i][j + 1], f[ii][j] + r[ii] - ii + abs(i - r[ii]));
                if (l[ii] >= 0)
                  f[i][j + 1] = min(f[i][j + 1], f[ii][j] + ii + i - 2 * l[ii]);
              }
            }

      int d = min(r[i] - i, i - l[i]);
      for (int j = mx - 1; j >= 0; j--)
      {
        int cur = f[i][j];
        for (int jj = 1; jj < a[i]; jj++)
        {
          cur += d * 2;
          if (cur > i * 2)
            break;
          f[i][j + jj] = min(f[i][j + jj], cur);
        }
      }
    }

  int ans = 0, total = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j <= mx; j++)
      if (f[i][j] <= i * 2)
        ans = max(ans, j + 1);
    if (a[i] > 0)
      total += a[i];
  }

  cout << total - ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 248 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 248 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 7 ms 716 KB Output is correct
29 Correct 5 ms 772 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 4 ms 760 KB Output is correct
34 Correct 3 ms 588 KB Output is correct
35 Correct 4 ms 844 KB Output is correct
36 Correct 3 ms 844 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 6 ms 856 KB Output is correct
39 Correct 4 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
41 Correct 5 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 248 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 7 ms 716 KB Output is correct
29 Correct 5 ms 772 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 4 ms 760 KB Output is correct
34 Correct 3 ms 588 KB Output is correct
35 Correct 4 ms 844 KB Output is correct
36 Correct 3 ms 844 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 6 ms 856 KB Output is correct
39 Correct 4 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
41 Correct 5 ms 844 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 2 ms 652 KB Output is correct
45 Correct 2 ms 716 KB Output is correct
46 Correct 1 ms 588 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 5 ms 716 KB Output is correct
49 Correct 3 ms 588 KB Output is correct
50 Correct 14 ms 748 KB Output is correct
51 Correct 17 ms 812 KB Output is correct
52 Correct 9 ms 584 KB Output is correct
53 Correct 24 ms 788 KB Output is correct
54 Correct 20 ms 780 KB Output is correct
55 Correct 18 ms 588 KB Output is correct
56 Correct 1 ms 716 KB Output is correct
57 Correct 5 ms 568 KB Output is correct
58 Correct 8 ms 716 KB Output is correct
59 Correct 6 ms 588 KB Output is correct
60 Correct 19 ms 716 KB Output is correct
61 Correct 5 ms 760 KB Output is correct
62 Correct 12 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 248 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 7 ms 716 KB Output is correct
29 Correct 5 ms 772 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 4 ms 760 KB Output is correct
34 Correct 3 ms 588 KB Output is correct
35 Correct 4 ms 844 KB Output is correct
36 Correct 3 ms 844 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 6 ms 856 KB Output is correct
39 Correct 4 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
41 Correct 5 ms 844 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 2 ms 652 KB Output is correct
45 Correct 2 ms 716 KB Output is correct
46 Correct 1 ms 588 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 5 ms 716 KB Output is correct
49 Correct 3 ms 588 KB Output is correct
50 Correct 14 ms 748 KB Output is correct
51 Correct 17 ms 812 KB Output is correct
52 Correct 9 ms 584 KB Output is correct
53 Correct 24 ms 788 KB Output is correct
54 Correct 20 ms 780 KB Output is correct
55 Correct 18 ms 588 KB Output is correct
56 Correct 1 ms 716 KB Output is correct
57 Correct 5 ms 568 KB Output is correct
58 Correct 8 ms 716 KB Output is correct
59 Correct 6 ms 588 KB Output is correct
60 Correct 19 ms 716 KB Output is correct
61 Correct 5 ms 760 KB Output is correct
62 Correct 12 ms 768 KB Output is correct
63 Execution timed out 3085 ms 143712 KB Time limit exceeded
64 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 248 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 7 ms 716 KB Output is correct
29 Correct 5 ms 772 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 4 ms 760 KB Output is correct
34 Correct 3 ms 588 KB Output is correct
35 Correct 4 ms 844 KB Output is correct
36 Correct 3 ms 844 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 6 ms 856 KB Output is correct
39 Correct 4 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
41 Correct 5 ms 844 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 2 ms 652 KB Output is correct
45 Correct 2 ms 716 KB Output is correct
46 Correct 1 ms 588 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 5 ms 716 KB Output is correct
49 Correct 3 ms 588 KB Output is correct
50 Correct 14 ms 748 KB Output is correct
51 Correct 17 ms 812 KB Output is correct
52 Correct 9 ms 584 KB Output is correct
53 Correct 24 ms 788 KB Output is correct
54 Correct 20 ms 780 KB Output is correct
55 Correct 18 ms 588 KB Output is correct
56 Correct 1 ms 716 KB Output is correct
57 Correct 5 ms 568 KB Output is correct
58 Correct 8 ms 716 KB Output is correct
59 Correct 6 ms 588 KB Output is correct
60 Correct 19 ms 716 KB Output is correct
61 Correct 5 ms 760 KB Output is correct
62 Correct 12 ms 768 KB Output is correct
63 Execution timed out 3085 ms 143712 KB Time limit exceeded
64 Halted 0 ms 0 KB -