Submission #378479

#TimeUsernameProblemLanguageResultExecution timeMemory
378479moratoBuilding 4 (JOI20_building4)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 5; const long long INF = 1e18; bool calculado[2 * MAXN][MAXN][2]; long long dp[2 * MAXN][MAXN][2]; long long a[2 * MAXN], b[2 * MAXN]; string ans; int n; long long solve(int i, int j, int f) { if (k > n || i - k > n || i > n + n) { // cout << i << ' ' << k << ' ' << n << '\n'; return -INF; } if (i == n + n) { assert(k == n); return 0; } if (calculado[i][k][f]) { return dp[i][k][f]; } calculado[i][k][f] = true; long long opcao1 = 0; long long opcao2 = 0; if (i == 0) { opcao1 = a[i] + solve(i + 1, k + 1, 0); opcao2 = b[i] + solve(i + 1, k, 1); return dp[i][k][f] = max(opcao1, opcao2); } assert(i > 0); if (!f) { opcao1 = (a[i] >= a[i - 1] ? a[i] + solve(i + 1, k + 1, 0) : -INF); opcao2 = (b[i] >= a[i - 1] ? b[i] + solve(i + 1, k, 1) : -INF); return dp[i][k][f] = max(opcao1, opcao2); } opcao1 = (a[i] >= b[i - 1] ? a[i] + solve(i + 1, k + 1, 0) : -INF); opcao2 = (b[i] >= b[i - 1] ? b[i] + solve(i + 1, k, 1) : -INF); return dp[i][k][f] = max(opcao1, opcao2); } void recu(int i, int k, int f) { if (i == n + n) { return; } if (a[i] + solve(i + 1, k + 1, 0) > b[i] + solve(i + 1, k, 1)) { ans += 'A'; recu(i + 1, k + 1, 0); } else { ans += 'B'; recu(i + 1, k, 1); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } for (int i = 0; i < 2 * n; i++) { cin >> b[i]; } long long valor = solve(0, 0, 0); if (valor < 0) { cout << -1 << '\n'; } else { recu(0, 0, 0); int cnta = 0; for (int i = 0; i < 2 * n; i++) cnta += ans[i] == 'A'; } assert(cnta == n); cout << ans << '\n'; } return 0; }

Compilation message (stderr)

building4.cpp: In function 'long long int solve(int, int, int)':
building4.cpp:16:6: error: 'k' was not declared in this scope
   16 |  if (k > n || i - k > n || i > n + n) {
      |      ^
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from building4.cpp:1:
building4.cpp:21:10: error: 'k' was not declared in this scope
   21 |   assert(k == n);
      |          ^
building4.cpp:24:19: error: 'k' was not declared in this scope
   24 |  if (calculado[i][k][f]) {
      |                   ^
building4.cpp:27:15: error: 'k' was not declared in this scope
   27 |  calculado[i][k][f] = true;
      |               ^
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from building4.cpp:1:
building4.cpp: In function 'int main()':
building4.cpp:79:10: error: 'cnta' was not declared in this scope
   79 |   assert(cnta == n);
      |          ^~~~
building4.cpp: At global scope:
building4.cpp:82:2: error: expected unqualified-id before 'return'
   82 |  return 0;
      |  ^~~~~~
building4.cpp:83:1: error: expected declaration before '}' token
   83 | }
      | ^