Submission #1287577

#TimeUsernameProblemLanguageResultExecution timeMemory
1287577adscodingBuilding 4 (JOI20_building4)C++20
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define BIT(mask, x) ((mask >> (x)) & 1) #define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i) #define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; // -------------------------------------- CON CUA BO HCN -------------------------------------- const int maxn = 1e6 + 3; int n, a[maxn], b[maxn]; pii dp[maxn][2]; // -------------------------------------------------------------------------------------------- pii merge(const pii &x, const pii &y) { return make_pair(min(x.first, y.first), max(x.second, y.second)); } bool check(const pii &x, int y) { return y >= x.first && y <= x.second; } void solve() { cin >> n; FOR(i, 1, n << 1) cin >> a[i]; FOR(i, 1, n << 1) cin >> b[i]; FOR(i, 1, n << 1) { FOR(j, 0, 1) dp[i][j] = {1e9 + 1, -1e9 - 1}; if (a[i] > a[i - 1]) dp[i][0] = merge(dp[i][0], make_pair(dp[i - 1][0].first + 1, dp[i - 1][0].second + 1)); if (a[i] > b[i - 1]) dp[i][0] = merge(dp[i][0], make_pair(dp[i - 1][1].first + 1, dp[i - 1][1].second + 1)); if (b[i] > a[i - 1]) dp[i][1] = merge(dp[i][1], dp[i - 1][0]); if (b[i] > b[i - 1]) dp[i][1] = merge(dp[i][1], dp[i - 1][1]); } int type = -1; if (check(dp[n << 1][0], n)) type = 0; else if (check(dp[n << 1][1], n)) type = 1; else return cout << -1, void(); string ans = ""; int u = n; FORD(i, n << 1, 1) { if (type == 0) { ans += 'A'; --u; if (a[i] > b[i - 1] && check(dp[i - 1][1], u)) type = 1; } else { ans += 'B'; if (b[i] > a[i - 1] && check(dp[i - 1][0], u)) type = 0; } } reverse(all(ans)); cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define TASK "TEST" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); return 0; } /* NOTES: Luon la mot doan lien tiep */

Compilation message (stderr)

building4.cpp: In function 'int main()':
building4.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building4.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...