# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
260175 | doowey | 건물 4 (JOI20_building4) | C++14 | 413 ms | 48436 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e6 + 100;
int A[2][N];
int low[N][2];
int high[N][2];
int main(){
fastIO;
int n;
cin >> n;
int m = 2 * n;
for(int j = 1; j <= m ; j ++ ){
for(int k = 0 ; k < 2; k ++ ){
low[j][k]=(int)1e9;
high[j][k]=0;
}
}
low[1][0] = 1;
high[1][0] = 1;
low[1][1] = 0;
high[1][1] = 0;
for(int i = 0 ; i < 2; i ++ ){
for(int j = 1; j <= m ; j ++ )
cin >> A[i][j];
}
int ni;
for(int j = 2; j <= m ; j ++ ){
for(int c = 0; c < 2; c ++ ){
for(int p = 0 ; p < 2; p ++ ){
if(A[p][j - 1] <= A[c][j]){
ni = low[j - 1][p] + (!c);
low[j][c] = min(low[j][c], ni);
ni = high[j - 1][p] + (!c);
high[j][c] = max(high[j][c], ni);
}
}
}
}
int cc = -1;
if(low[m][0] <= n && n <= high[m][0]){
cc = 0;
}
else if(low[m][1] <= n && n <= high[m][1]){
cc = 1;
}
else{
cout << "-1\n";
return 0;
}
int cval = n;
int nval;
vector<int> sol;
sol.push_back(cc);
bool broke;
for(int j = m ; j > 1; j -- ){
cval -= !cc;
broke = false;
for(int pv = 0 ; pv < 2; pv ++ ){
if(low[j - 1][pv] <= cval && cval <= high[j - 1][pv] && A[pv][j-1] <= A[cc][j]){
cc = pv;
sol.push_back(cc);
broke = true;
break;
}
}
}
reverse(sol.begin(), sol.end());
for(auto x : sol){
cout << char('A' + x);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |