Submission #598560

# Submission time Handle Problem Language Result Execution time Memory
598560 2022-07-18T13:58:02 Z piOOE Rope (JOI17_rope) C++17
15 / 100
1320 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

void merge(vector<int> &a, vector<int> &b) {
  for (int x: b) {
    a.push_back(x);
  }
}

void rollback(vector<int>& a, int x) {
  while (x--) {
    a.pop_back();
  }
}

const int N = 15;

int a[N], ans[N];

int s, n, m;

void rec(int L, int R, vector<vector<int>> &g) {
  if (L == s && R == s + 1) {
    for (int c1 = 0; c1 < m; ++c1) {
      for (int c2 = 0; c2 < m; ++c2) {
        int now = 0;
        for (int x: g[s]) {
          now += a[x] != c1;
        }
        for (int x: g[s + 1]) {
          now += a[x] != c2;
        }
        ans[c1] = min(ans[c1], now);
        ans[c2] = min(ans[c2], now);
      }
    }
    return;
  }
  for (int i = L + 1; i <= s; ++i) {
    if (i + (i - L) - 1 > R) {
      break;
    }
    for (int j = L; j < i; ++j) {
      merge(g[i + (i - j) - 1], g[j]);
    }
    rec(i, R, g);
    for (int j = L; j < i; ++j) {
      rollback(g[i + (i - j) - 1], g[j].size());
    }
  }
  for (int i = R - 1; i >= s + 1; --i) {
    if (i - (R - i) + 1 < s) {
      break;
    }
    for (int j = R; j > i; --j) {
      merge(g[i - (j - i) + 1], g[j]);
    }
    rec(L, i, g);
    for (int j = R; j > i; --j) {
      rollback(g[i - (j - i) + 1], g[j].size());
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  memset(ans, 0x3f, sizeof(ans));
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
  }
  vector g(n, vector<int>(1));
  for (int i = 0; i < n; ++i) {
    g[i][0] = i;
  }
  for (s = 0; s < n - 1; ++s) {
    rec(0, n - 1, g);
  }
  for (int i = 0; i < m; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1320 ms 296 KB Output is correct
2 Correct 42 ms 212 KB Output is correct
3 Correct 129 ms 292 KB Output is correct
4 Correct 280 ms 212 KB Output is correct
5 Correct 74 ms 304 KB Output is correct
6 Correct 140 ms 300 KB Output is correct
7 Correct 328 ms 300 KB Output is correct
8 Correct 689 ms 296 KB Output is correct
9 Correct 572 ms 296 KB Output is correct
10 Correct 425 ms 300 KB Output is correct
11 Correct 4 ms 320 KB Output is correct
12 Correct 4 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1320 ms 296 KB Output is correct
2 Correct 42 ms 212 KB Output is correct
3 Correct 129 ms 292 KB Output is correct
4 Correct 280 ms 212 KB Output is correct
5 Correct 74 ms 304 KB Output is correct
6 Correct 140 ms 300 KB Output is correct
7 Correct 328 ms 300 KB Output is correct
8 Correct 689 ms 296 KB Output is correct
9 Correct 572 ms 296 KB Output is correct
10 Correct 425 ms 300 KB Output is correct
11 Correct 4 ms 320 KB Output is correct
12 Correct 4 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Runtime error 1 ms 340 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1320 ms 296 KB Output is correct
2 Correct 42 ms 212 KB Output is correct
3 Correct 129 ms 292 KB Output is correct
4 Correct 280 ms 212 KB Output is correct
5 Correct 74 ms 304 KB Output is correct
6 Correct 140 ms 300 KB Output is correct
7 Correct 328 ms 300 KB Output is correct
8 Correct 689 ms 296 KB Output is correct
9 Correct 572 ms 296 KB Output is correct
10 Correct 425 ms 300 KB Output is correct
11 Correct 4 ms 320 KB Output is correct
12 Correct 4 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Runtime error 1 ms 340 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1320 ms 296 KB Output is correct
2 Correct 42 ms 212 KB Output is correct
3 Correct 129 ms 292 KB Output is correct
4 Correct 280 ms 212 KB Output is correct
5 Correct 74 ms 304 KB Output is correct
6 Correct 140 ms 300 KB Output is correct
7 Correct 328 ms 300 KB Output is correct
8 Correct 689 ms 296 KB Output is correct
9 Correct 572 ms 296 KB Output is correct
10 Correct 425 ms 300 KB Output is correct
11 Correct 4 ms 320 KB Output is correct
12 Correct 4 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Runtime error 1 ms 340 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1320 ms 296 KB Output is correct
2 Correct 42 ms 212 KB Output is correct
3 Correct 129 ms 292 KB Output is correct
4 Correct 280 ms 212 KB Output is correct
5 Correct 74 ms 304 KB Output is correct
6 Correct 140 ms 300 KB Output is correct
7 Correct 328 ms 300 KB Output is correct
8 Correct 689 ms 296 KB Output is correct
9 Correct 572 ms 296 KB Output is correct
10 Correct 425 ms 300 KB Output is correct
11 Correct 4 ms 320 KB Output is correct
12 Correct 4 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Runtime error 1 ms 340 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -