CSES - Datatähti 2022 loppu - Results
Submission details
Task:Peli
Sender:hltk
Submission time:2022-01-22 21:21:57 +0200
Language:C++17
Status:COMPILE ERROR

Compiler report

output/cc4mnts3.o: In function `main':
code.cpp:(.text.startup+0x6b): relocation truncated to fit: R_X86_64_PC32 against symbol `s[abi:cxx11]' defined in .bss section in output/cc4mnts3.o
code.cpp:(.text.startup+0x8c): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in output/cc4mnts3.o
code.cpp:(.text.startup+0xe8): relocation truncated to fit: R_X86_64_PC32 against symbol `s[abi:cxx11]' defined in .bss section in output/cc4mnts3.o
code.cpp:(.text.startup+0x759): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in output/cc4mnts3.o
code.cpp:(.text.startup+0xe3b): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in output/cc4mnts3.o
output/cc4mnts3.o: In function `_GLOBAL__sub_I__Z1sB5cxx11':
code.cpp:(.text.startup+0xe53): relocation truncated to fit: R_X86_64_PC32 against `.bss'
code.cpp:(.text.startup+0xe71): relocation truncated to fit: R_X86_64_PC32 against `.bss'...

Code

#pragma GCC optimize("O3,unroll-all-loops")
#include <bits/stdc++.h>
using namespace std;
string s;
int ans;
const int N = 100001;
int ab[N][51][51];
int ac[N][51][51];
int bc[N][51][51];
const int INF = 1e9;
int &state(int i, int a, int b, int c) {
  if (!a) return bc[i][b][c];
  if (!b) return ac[i][a][c];
  return ab[i][a][b];
}
void cmax(int &x, int y) {
  x = max(x, y);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  if (k < 3) {
    cout << 0 << endl;
  } else {
    cin >> s;
    for (int i = 0; i <= n; ++i) {
      for (int a = 0; a <= k; ++a) {
        for (int b = 0; b <= k; ++b) {
          for (int c = 0; c <= k; ++c) {
            if (a && b && b) break;
            if (a || b || c) {
              state(i, a, b, c) = -INF;
            }
            if (i && (!a || !b || !c) && a + b + c <= k) {
              cmax(state(i, a, b, c), state(i - 1, a, b, c));
            }
          }
        }
      }
      if (i == 0) continue;
      for (int a = 0; a <= k; ++a) {
        for (int b = 0; b <= k - a; ++b) {
          for (int c = 0; c <= k - a - b; ++c) {
            if (a && b && c) break;
            if (a && b && s[i - 1] == 'C' && a + b + c < k) {
              cmax(state(i, a - 1, b - 1, c), state(i - 1, a, b, c) + 1);
            }
            if (a && c && s[i - 1] == 'B' && a + b + c < k) {
              cmax(state(i, a - 1, b, c - 1), state(i - 1, a, b, c) + 1);
            }
            if (b && c && s[i - 1] == 'A' && a + b + c < k) {
              cmax(state(i, a, b - 1, c - 1), state(i - 1, a, b, c) + 1);
            }
            if (s[i - 1] == 'A' && a + 1 <= k && a + b + c + 1 <= k && (!b || !c)) {
              cmax(state(i, a + 1, b, c), state(i - 1, a, b, c));
            }
            if (s[i - 1] == 'B' && b + 1 <= k && a + b + c + 1 <= k && (!a || !c)) {
              cmax(state(i, a, b + 1, c), state(i - 1, a, b, c));
            }
            if (s[i - 1] == 'C' && c + 1 <= k && a + b + c + 1 <= k && (!a || !b)) {
              cmax(state(i, a, b, c + 1), state(i - 1, a, b, c));
            }
          }
        }
      }
      for (int a = 0; a <= k; ++a) {
        for (int b = 0; b <= k - a; ++b) {
          for (int c = 0; c <= k - a - b; ++c) {
            if (a && b && c) break;
            cmax(ans, state(i, a, b, c));
          }
        }
      }
    }
    cout << ans << endl;
  }
}