Submission #962631

# Submission time Handle Problem Language Result Execution time Memory
962631 2024-04-14T04:36:52 Z Cookie Building 4 (JOI20_building4) C++14
0 / 100
3 ms 6748 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e18 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
int n;
int mx[mxn + 1][2], mn[mxn + 1][2], a[mxn + 1], b[mxn + 1];
void ckmin(int &a, int b){
    if(a > b)a = b;
}
void ckmax(int &a, int b){
    if(a < b)a = b;
}
void solve(){
   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++){
       mn[i][0] = mn[i][1] = inf; mx[i][0] = mx[i][1] = 0;
   }
   //minimum and maximum Bs
   mn[1][0] = mx[1][0] = 0; mn[1][1] = mx[1][1] = 1;
   for(int i = 1; i < 2 * n; i++){
       if(a[i] <= a[i + 1]){
           ckmin(mn[i + 1][0], mn[i][0]); ckmax(mx[i + 1][0], mx[i][0]);
       }if(a[i] <= b[i + 1]){
           ckmin(mn[i + 1][1], mn[i][0] + 1); ckmax(mx[i + 1][1], mx[i][0] + 1);
       }if(b[i] <= a[i + 1]){
           ckmin(mn[i + 1][0], mn[i][1]); ckmax(mx[i + 1][0], mx[i][1]);
       }if(b[i] <= b[i + 1]){
           ckmin(mn[i + 1][1], mn[i][1] + 1); ckmax(mx[i + 1][1], mx[i][1] + 1);
       }
   }
   int id = 2 * n, type;
   if(mx[2 * n][0] >= n && mn[2 * n][0] <= n)type = 0;
   else if(mx[2 * n][1] >= n && mn[2 * n][1] <= n)type = 1;
   else{
       cout << -1; return;
   }
   int taken = 0;
   string ans = "";
   while(1){
       ans += ((type == 0) ? 'A' : 'B');
       if(id == 1)break;
       taken += type;
       int v = ((type == 0) ? a[id] : b[id]);
       if(a[id - 1] <= v && mx[id - 1][0] + taken >= n && mn[id - 1][0] + taken <= n)type = 0;
       else if(b[id - 1] <= v && mx[id - 1][1] + taken >= n && mn[id - 1][1] + taken <= n)type = 1; 
       
       id--;
   }
   reverse(ALL(ans));
   cout << ans;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("DATA.inp", "r", stdin);
    //freopen("DATA.out", "w", stdout);
    int tt; tt = 1;
    while(tt--){
        solve();
 
    }
    return(0);
}

Compilation message

building4.cpp: In function 'void solve()':
building4.cpp:42:30: warning: overflow in conversion from 'long long int' to 'int' changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
   42 |        mn[i][0] = mn[i][1] = inf; mx[i][0] = mx[i][1] = 0;
      |                              ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 3 ms 6488 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6676 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Incorrect 2 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 3 ms 6488 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6676 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Incorrect 2 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -