# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
659422 | Ronin13 | Building 4 (JOI20_building4) | C++14 | 0 ms | 212 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
pii merg(pii a, pii b){
return {min(a.f, b.f), max(a.s, b.s)};
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int n; cin >> n;
int a[2 * n + 1][2];
for(int j = 0; j < 2; j++){
for(int i = 1; i <= 2 * n; i++)
cin >> a[i][j];
}
pii dp[2 * n + 1][2];
dp[1][0] = {0, 0};
dp[1][1] = {1, 1};
for(int i = 2; i <= 2 * n; i++){
for(int j = 0; j < 2; j++){
pii x = {1e9, -1e9};
pii y = {1e9, -1e9};
if(a[i][j] >= a[i - 1][0]){
x = {dp[i - 1][0].f + j, dp[i - 1][0].s + j};
}
if(a[i][j] >= a[i - 1][1]){
y = {dp[i - 1][1].f + j, dp[i - 1][1].s + j};
}
dp[i][j] = merg(x, y);
}
}
/*for(int i = 1; i <= 2 * n; i++){
for(int j = 0; j < 2; j++){
cout << dp[i][j].f << ' ' << dp[i][j].s << " ";
}
cout << "\n";
}*/
int last;
int cur = n;
string ans = "";
if(dp[2 * n][0].f > n || dp[2 * n][0].s < n){
if(dp[2 * n][1].f > n || dp[2 * n][1].s < n){
cout << -1 << "\n";
return 0;
}
last = 1;
cur--;
ans += 'B';
}
else{
last = 0;
ans += 'A';
}
for(int i = 2 * n - 1; i >= 1; i--){
for(int j = 0; j < 2; j++){
if(a[i][j] > a[i + 1][last]) continue;
if(dp[i][j].f <= cur && dp[i][j].s >= cur){
last = j;
cur -= j;
break;
}
}
if(last) ans += 'B';
else ans += 'A';
}
reverse(ans.begin(), ans.end());
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |