제출 #1152321

#제출 시각아이디문제언어결과실행 시간메모리
1152321mingga건물 4 (JOI20_building4)C++20
0 / 100
2 ms584 KiB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 1e6 + 7;
int n, a[N], b[N];
int mn[N][2], mx[N][2];

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    #define task ""
    if(fopen(task ".INP", "r")) {
        freopen(task ".INP", "r", stdin);
        freopen(task ".OUT", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= 2 * n; i++) cin >> a[i];
    for(int i = 1; i <= 2 * n; i++) cin >> b[i];
    for(int i = 1; i <= 2 * n; i++) {
        if(a[i] >= a[i - 1]) {
            mx[i][0] = max(mx[i - 1][0], mx[i][0]);
            mn[i][0] = min(mn[i - 1][0], mn[i][0]);
        }
        if(b[i] >= a[i - 1]) {
            mx[i][1] = max(mx[i][1], mx[i - 1][0] + 1);
            mn[i][1] = min(mn[i][1], mn[i - 1][0] + 1);
        }
        if(a[i] >= b[i - 1]) {
            mx[i][0] = max(mx[i - 1][1], mx[i][0]);
            mn[i][0] = min(mn[i - 1][1], mn[i][0]);
        }
        if(b[i] >= b[i - 1]) {
            mx[i][1] = max(mx[i][1], mx[i - 1][1] + 1);
            mn[i][1] = min(mn[i][1], mn[i - 1][1] + 1);
        }
    }
    int cur_i = 2 * n, cur_j;
    vector<char> ans;
    if(mx[n * 2][0] >= n and mn[n * 2][0] <= n) {
        cur_j = 0;
    } else if(mx[n * 2][1] >= n and mn[n * 2][1] <= n) {
        cur_j = 1;
    } else {
        cout << -1;
        return 0;
    }
    int m = n;
    while(sz(ans) < 2 * n) {
        if(cur_j == 0) ans.pb('A');
        else ans.pb('B');
        cur_i--;
        m -= cur_j;
        if(mx[cur_i][cur_j] < m or mn[cur_i][cur_j] > m) {
            cur_j ^= 1;
        }
    }
    reverse(all(ans));
    for(auto x : ans) cout << x;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

컴파일 시 표준 에러 (stderr) 메시지

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