Submission #1135840

#TimeUsernameProblemLanguageResultExecution timeMemory
1135840ThanhsBuilding 4 (JOI20_building4)C++20
0 / 100
6 ms12872 KiB
#include <bits/stdc++.h> using namespace std; #define name "TENBAI" #define fi first #define se second #define int long long #define endl '\n' #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 4e5 + 5; int n, dp[NM][2][2], a[NM][2]; void solve() { memset(dp, -1, sizeof dp); cin >> n; for (int i = 0; i < 2; i++) for (int j = 1; j <= 2 * n; j++) cin >> a[j][i]; dp[1][0][0] = dp[1][0][1] = 1; dp[1][1][0] = dp[1][1][1] = 0; for (int i = 1; i < 2 * n; i++) for (int j = 0; j < 2; j++) for (int t = 0; t < 2 && ~dp[i][j][t]; t++) for (int k = 0; k < 2; k++) { if (a[i + 1][k] < a[i][j]) continue; if (dp[i + 1][k][0] == -1) dp[i + 1][k][0] = dp[i + 1][k][1] = dp[i][j][t] + !k; else { setmin(dp[i + 1][k][0], dp[i][j][t] + !k); setmax(dp[i + 1][k][1], dp[i][j][t] + !k); } } string ans = ""; if (dp[2 * n][0][0] <= n && dp[2 * n][0][1] >= n) { ans += 'A'; int i = 2 * n, cr = 1; while (i > 1) { for (int j = 0; j < 2; j++) if (cr + dp[i - 1][j][0] <= n && cr + dp[i - 1][j][1] >= n) { ans += char('A' + j); cr += !j; break; } i--; } reverse(ans.begin(), ans.end()); cout << ans; return; } if (dp[2 * n][1][0] <= n && dp[2 * n][1][1] >= n) { ans += 'B'; int i = 2 * n, cr = 0; while (i > 1) { for (int j = 0; j < 2; j++) if (cr + dp[i - 1][j][0] <= n && cr + dp[i - 1][j][1] >= n) { ans += char('A' + j); cr += !j; break; } i--; } reverse(ans.begin(), ans.end()); cout << ans; return; } cout << -1; } signed main() { if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } else if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tc = 1; // cin >> tc; while (tc--) solve(); }

Compilation message (stderr)

building4.cpp: In function 'int main()':
building4.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
building4.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building4.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building4.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...