# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1164381 | hainam2k9 | 건물 4 (JOI20_building4) | C++20 | 154 ms | 24012 KiB |
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e6+5;
const string NAME = "";
int n;
bool dp[4005][2005][2];
pair<int,int> p[MAXN];
vector<char> v;
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n;
for(int i = 1; i<=n<<1; ++i)
cin >> p[i].fi;
for(int i = 1; i<=n<<1; ++i)
cin >> p[i].se;
dp[1][0][0]=dp[1][1][1]=1;
for(int i = 2; i<=n<<1; ++i)
for(int j = 0; j<=min(i,n); ++j){
dp[i][j][0]|=dp[i-1][j][0]&(p[i].fi>=p[i-1].fi);
dp[i][j][0]|=dp[i-1][j][1]&(p[i].fi>=p[i-1].se);
dp[i][j][1]|=dp[i-1][j-1][0]&(p[i].se>=p[i-1].fi);
dp[i][j][1]|=dp[i-1][j-1][1]&(p[i].se>=p[i-1].se);
}
if(!dp[n<<1][n][0]&&!dp[n<<1][n][1]) return cout << -1, 0;
for(int i=n<<1, cnt=n; i>0; --i){
if(dp[i][cnt][0]&&(i==2*n||p[i].fi<=(v.back()=='A' ? p[i+1].fi : p[i+1].se))) v.pb('A');
else v.pb('B'), --cnt;
}
reverse(v.begin(),v.end());
for(char& c : v) cout << c;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |