Submission #598723

# Submission time Handle Problem Language Result Execution time Memory
598723 2022-07-18T19:43:59 Z piOOE Rope (JOI17_rope) C++17
45 / 100
2500 ms 3840 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 100000, M = 10;

int a[N], ans[M];
int pref[2][2][N], suf[2][2][N]; // {first or second, left or right}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  memset(ans, 0x3f, sizeof(ans));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
  }
  for (int c1 = 0; c1 < m; ++c1) {
    for (int c2 = 0; c2 < m; ++c2) {
      int c[2] = {c1, c2};

      pref[0][0][0] = pref[0][1][0] = a[0] != c[0];
      pref[1][0][0] = pref[1][1][0] = a[0] != c[1];
      for (int i = 1; i < n; ++i) {
        pref[1][1][i] = (a[i] != c[1]) + pref[1][0][i - 1];
        pref[1][0][i] = (a[i] != c[1]) + min(pref[1][1][i - 1], pref[0][0][i - 1]);
        pref[0][1][i] = (a[i] != c[0]) + min(pref[0][0][i - 1], pref[1][1][i - 1]);
        pref[0][0][i] = (a[i] != c[0]) + pref[0][1][i - 1];
      }

      suf[0][0][n - 1] = suf[0][1][n - 1] = a[n - 1] != c[0];
      suf[1][0][n - 1] = suf[1][1][n - 1] = a[n - 1] != c[1];
      for (int i = n - 2; i > -1; --i) {
        suf[1][1][i] = (a[i] != c[1]) + suf[1][0][i + 1];
        suf[1][0][i] = (a[i] != c[1]) + min(suf[1][1][i + 1], suf[0][0][i + 1]);
        suf[0][1][i] = (a[i] != c[0]) + min(suf[0][0][i + 1], suf[1][1][i + 1]);
        suf[0][0][i] = (a[i] != c[0]) + suf[0][1][i + 1];
      }

      for (int i = 0; i < n - 1; ++i) {
        int now = pref[0][0][i] + suf[1][1][i + 1];
        ans[c1] = min(ans[c1], now);
        ans[c2] = min(ans[c2], now);
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 120 ms 3840 KB Output is correct
28 Correct 27 ms 3796 KB Output is correct
29 Correct 99 ms 3824 KB Output is correct
30 Correct 41 ms 3820 KB Output is correct
31 Correct 122 ms 3796 KB Output is correct
32 Correct 27 ms 3836 KB Output is correct
33 Correct 100 ms 3820 KB Output is correct
34 Correct 38 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 120 ms 3840 KB Output is correct
28 Correct 27 ms 3796 KB Output is correct
29 Correct 99 ms 3824 KB Output is correct
30 Correct 41 ms 3820 KB Output is correct
31 Correct 122 ms 3796 KB Output is correct
32 Correct 27 ms 3836 KB Output is correct
33 Correct 100 ms 3820 KB Output is correct
34 Correct 38 ms 3796 KB Output is correct
35 Execution timed out 2575 ms 3724 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 120 ms 3840 KB Output is correct
28 Correct 27 ms 3796 KB Output is correct
29 Correct 99 ms 3824 KB Output is correct
30 Correct 41 ms 3820 KB Output is correct
31 Correct 122 ms 3796 KB Output is correct
32 Correct 27 ms 3836 KB Output is correct
33 Correct 100 ms 3820 KB Output is correct
34 Correct 38 ms 3796 KB Output is correct
35 Execution timed out 2575 ms 3724 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 120 ms 3840 KB Output is correct
28 Correct 27 ms 3796 KB Output is correct
29 Correct 99 ms 3824 KB Output is correct
30 Correct 41 ms 3820 KB Output is correct
31 Correct 122 ms 3796 KB Output is correct
32 Correct 27 ms 3836 KB Output is correct
33 Correct 100 ms 3820 KB Output is correct
34 Correct 38 ms 3796 KB Output is correct
35 Execution timed out 2575 ms 3724 KB Time limit exceeded
36 Halted 0 ms 0 KB -