Submission #915395

#TimeUsernameProblemLanguageResultExecution timeMemory
915395XXBabaProBerkayBuilding 4 (JOI20_building4)C++17
0 / 100
1 ms580 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second using ll = long long; const int INF = 1e9 + 7; const int MOD = 998244353; int N; map<int, map<int, int>> dp; vector<int> A, B, ans; vector<char> s; bool f(int i, int a, int b) { if (i == (N << 1)) { if (a == b) { for (char j : s) cout << j; cout << '\n'; return 1; } return 0; } if (dp[a][b] != 0) return (dp[a][b] == -1 ? 0 : 1); dp[a][b] = 0; if (i == 0 || A[i] >= ans[i - 1]) { ans[i] = A[i]; s[i] = 'A'; dp[a][b] |= f(i + 1, a + 1, b); } if ((i == 0 || B[i] >= ans[i - 1]) && !dp[a][b]) { ans[i] = B[i]; s[i] = 'B'; dp[a][b] |= f(i + 1, a, b + 1); } dp[a][b] = (dp[a][b] == 0 ? -1 : dp[a][b]); return dp[a][b] == -1 ? 0 : 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N; A.resize(N << 1); B.resize(N << 1); ans.resize(N << 1); s.resize(N << 1); for (int &i : A) cin >> i; for (int &i : B) cin >> i; bool res = f(0, 0, 0); if (!res) cout << -1 << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...