Submission #782964

#TimeUsernameProblemLanguageResultExecution timeMemory
782964kamelfanger83Building 4 (JOI20_building4)C++17
0 / 100
3 ms340 KiB
#include <iostream> #include <vector> #include <limits> #include <string> #include <cassert> #include <algorithm> using namespace std; int main(){ int n; cin >> n; n <<= 1; vector<pair<int, int>> ops (n); for (int i = 0; i < n; ++i) cin >> ops[i].first; for (int i = 0; i < n; ++i) cin >> ops[i].second; vector<pair<int, int>> lowers (n, {numeric_limits<int>::max(), numeric_limits<int>::max()}), uppers (n, {numeric_limits<int>::min(), numeric_limits<int>::min()}); lowers[0].first = 1; lowers[0].second = 0; uppers[0].first = 1; uppers[0].second = 0; for (int i = 1; i < n; ++i) { if (ops[i].first >= ops[i - 1].first) { lowers[i].first = lowers[i - 1].first; uppers[i].first = uppers[i - 1].first; } if (ops[i].first >= ops[i - 1].second) { lowers[i].first = min(lowers[i].first, lowers[i - 1].second); uppers[i].first = max(uppers[i].first, uppers[i - 1].second); } if (lowers[i].first != numeric_limits<int>::max()) lowers[i].first++; uppers[i].first++; if (ops[i].second >= ops[i - 1].first) { lowers[i].second = lowers[i - 1].first; uppers[i].second = uppers[i - 1].first; } if (ops[i].second >= ops[i - 1].second) { lowers[i].second = min(lowers[i].first, lowers[i - 1].second); uppers[i].second = max(uppers[i].first, uppers[i - 1].second); } } auto isin = [](int l, int r, int v){ return l <= v && v <= r; }; if (!isin(lowers.back().first, uppers.back().first, n/2) && !isin(lowers.back().second, uppers.back().second, n/2)) cout << -1 << "\n"; else { string ANS; int tbd = n/2; for (int i = n - 1; i >= 0; --i) { if (isin(lowers[i].first, uppers[i].first, tbd)){ ANS.push_back('A'); tbd--; } else if (isin(lowers[i].second, uppers[i].second, tbd)){ ANS.push_back('B'); } else{ assert(false); } } assert(tbd == 0); reverse(ANS.begin(), ANS.end()); cout << ANS; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...