Submission #206669

#TimeUsernameProblemLanguageResultExecution timeMemory
206669opukittpceno_hhrRope (JOI17_rope)C++17
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <unordered_set> #include <unordered_map> #include <numeric> #include <ctime> #include <bitset> #include <complex> #include <random> using namespace std; const int N = 15; const int INF = 1e9 + 239; const int NONE = -1; int eq(int a, int b) { if (a == NONE || b == NONE) { return 1; } else { return a == b; } } int dp[N][N + 1]; int cans(vector<int> s) { int n = (int)s.size(); for (int i = 0; i < N; i++) { for (int j = 0; j <= N; j++) { dp[i][j] = -1; } } function<int(int, int)> can = [&](int i, int len) { if (len % 2 == 1) { return n; } if (len == 0) { return 0; } if (dp[i][len] == -1) { dp[i][len] = can(i + 1, len - 2) + !eq(s[i], s[i + len - 1]); } return dp[i][len]; }; vector<int> pdp(n + 1, INF); pdp[0] = 0; for (int i = 0; i < n; i++) { for (int len = 2; i + len <= n; len++) { pdp[i + len / 2] = min(pdp[i + len / 2], pdp[i] + can(i, len)); } } reverse(s.begin(), s.end()); for (int i = 0; i < N; i++) { for (int j = 0; j <= N; j++) { dp[i][j] = -1; } } vector<int> sdp(n + 1, INF); sdp[0] = 0; for (int i = 0; i < n; i++) { for (int len = 2; i + len <= n; len++) { sdp[i + len / 2] = min(sdp[i + len / 2], sdp[i] + can(i, len)); } } int ans = n; for (int i = 0; i <= n; i++) { if (n - 2 - i >= 0) { ans = min(ans, pdp[i] + sdp[n - 2 - i]); } } return ans == 0; } int solve(vector<int> s, int a, int b) { int n = (int)s.size(); int ans = n; for (int i = 0; i < (1 << n); i++) { vector<int> ts = s; for (int j = 0; j < n; j++) { if ((i >> j) & 1) { ts[j] = a; } else { ts[j] = b; } } if (cans(ts)) { int c = 0; for (int j = 0; j < n; j++) { c += !eq(s[j], ts[j]); } ans = min(ans, c); } } for (auto t : s) { ans += (t == NONE); } return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); // vector<int> a; // a = {2, 2, 1, 1, NONE, NONE, 2, 1, 1, 2}; // cout << solve(a, 2, 1) << endl; // vector<int> a; // a = {2, 2, 1, 1, 1, 1, 2, 1, 1, 2}; // cout << cans(a) << endl; int n, m; cin >> n >> m; vector<int> a(n); for (auto &t : a) { cin >> t; t--; } vector<int> ans(m, n); for (int i = 0; i < m; i++) { for (int j = i; j < m; j++) { vector<int> ta = a; for (auto &x : ta) { if (x != i && x != j) x = NONE; } int v = solve(ta, i, j); ans[i] = min(ans[i], v); ans[j] = min(ans[j], v); } } for (auto t : ans) { cout << t << '\n'; } }

Compilation message (stderr)

rope.cpp: In function 'int cans(std::vector<int>)':
rope.cpp:45:2: error: 'function' was not declared in this scope
  function<int(int, int)> can = [&](int i, int len) {
  ^~~~~~~~
rope.cpp:45:2: note: suggested alternative: 'union'
  function<int(int, int)> can = [&](int i, int len) {
  ^~~~~~~~
  union
rope.cpp:45:23: error: expression list treated as compound expression in functional cast [-fpermissive]
  function<int(int, int)> can = [&](int i, int len) {
                       ^
rope.cpp:45:11: error: expected primary-expression before 'int'
  function<int(int, int)> can = [&](int i, int len) {
           ^~~
rope.cpp:61:54: error: 'can' was not declared in this scope
    pdp[i + len / 2] = min(pdp[i + len / 2], pdp[i] + can(i, len));
                                                      ^~~
rope.cpp:61:54: note: suggested alternative: 'cans'
    pdp[i + len / 2] = min(pdp[i + len / 2], pdp[i] + can(i, len));
                                                      ^~~
                                                      cans
rope.cpp:74:54: error: 'can' was not declared in this scope
    sdp[i + len / 2] = min(sdp[i + len / 2], sdp[i] + can(i, len));
                                                      ^~~
rope.cpp:74:54: note: suggested alternative: 'cans'
    sdp[i + len / 2] = min(sdp[i + len / 2], sdp[i] + can(i, len));
                                                      ^~~
                                                      cans