Submission #947391

#TimeUsernameProblemLanguageResultExecution timeMemory
947391weakweakweakBuilding 4 (JOI20_building4)C++17
11 / 100
43 ms12952 KiB
//joisc怎麼也有水題阿 #include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second int n, a[510000], b[510000]; pii dp[510000][2]; pii dead = {1000000, -1000000}; int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n * 2; i++) cin >> a[i]; for (int i = 1; i <= n * 2; i++) cin >> b[i]; a[0] = b[0] = -1, dp[0][0] = dp[0][1] = {0, 0}; for (int i = 1; i <= n * 2; i++) dp[i][0] = dp[i][1] = dead; for (int i = 1; i <= n * 2; i++) { { bool y0 = (a[i] >= a[i - 1]) and (dp[i - 1][0] != dead), y1 = (a[i] >= b[i-1]) and (dp[i - 1][1] != dead); if (y0 and y1) { dp[i][0] . fs = min(dp[i - 1][0].fs, dp[i - 1][1].fs) + 1; dp[i][0] . sc = max(dp[i - 1][0].sc, dp[i - 1][1].sc) + 1; } else if (y0) dp[i][0] = {dp[i - 1][0].fs + 1, dp[i - 1][0].sc + 1}; else if (y1) dp[i][0] = {dp[i - 1][1].fs + 1, dp[i - 1][1].sc + 1}; } { bool y0 = (b[i] >= a[i - 1]) and (dp[i - 1][0] != dead), y1 = (b[i] >= b[i-1]) and (dp[i - 1][1] != dead); if (y0 and y1) { dp[i][1] . fs = min(dp[i - 1][0].fs, dp[i - 1][1].fs); dp[i][1] . sc = max(dp[i - 1][0].sc, dp[i - 1][1].sc); } else if (y0) dp[i][1] = dp[i - 1][0]; else if (y1) dp[i][1] = dp[i - 1][1]; } } int now = 2; if (dp[n * 2][0] != dead and dp[n * 2][0].fs <= n and dp[n * 2][0].sc >= n) now = 0; if (dp[n * 2][1] != dead and dp[n * 2][1].fs <= n and dp[n * 2][1].sc >= n) now = 1; if (now == 2) { cout << "-1\n"; return 0; } string ans; int used = 0; for (int i = n * 2; i >= 1; i--) { int me = a[i]; if (now == 1) ans += "B", me = b[i]; else ans += "A", used++; if (dp[i - 1][1] != dead and dp[i - 1][1].fs + used <= n and dp[i - 1][1].sc + used >= n and b[i -1] <= me) now = 1; else now = 0; } reverse(ans.begin(), ans.end()); cout << ans << '\n'; return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...