Submission #834122

#TimeUsernameProblemLanguageResultExecution timeMemory
834122ALeonidouPrisoner Challenge (IOI22_prison)C++17
0 / 100
1149 ms1699420 KiB
#include "prison.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define sz(x) (ll)x.size()
#define F first
#define S second
#define pb push_back
#define MID ((l+r)/2)
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
#define dbg5(x,y,z,a,b) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<" "<<#a<<": "<<a<<" "<<#b<<": "<<b<<endl;

typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
typedef pair<ii,ii> i4;
typedef pair <ll, i4> i5;

void printVct(vi &v, string s = ""){
    cout<<s<<": ";
    for (ll i=0; i<sz(v); i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;
}

void printVct2D(vector <vi> &v, string s = ""){
    cout<<s<<": "<<endl;
    for (ll i=0; i<sz(v); i++){
        cout<<i<<": ";
        for (ll j =0; j<sz(v[i]); j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
}

vector <vi> s;

ll next_free = 0;
queue<i5> q;
void addQ(ll a, ll b, ll c, ll d, ll e){
    q.push(i5(a, i4(ii(b,c), ii(d,e))));
    next_free ++;
}

bool calc(ll u, ll l, ll r, ll resVal){
    ll new_range= (r-l+1);
    ll val = next_free;
    if (new_range == 1) 
        val = resVal;
    for (ll i=l; i<=r; i++) 
        s[u][i] = val; 
    return (new_range>1);
}

vector<vi> devise_strategy(int n) {


    addQ(0,1,n,1,n);

    i5 f;
    ll u, al,ar,bl,br;
    ll mid;
    while (!q.empty()){
        f = q.front();
        q.pop();
        u = f.F;
        al = f.S.F.F;
        ar = f.S.F.S;
        bl = f.S.S.F;
        br = f.S.S.S;

        // dbg5(u,al,ar,bl,br);

        s.pb(vi(n+1));

        ll range_a = ar - al + 1;
        ll range_b = br - bl + 1;
        if (range_a == range_b){
            //check A
            s[u][0] = 0;
            if (range_a > 2){
                mid = (al + ar) / 2;
                if (calc(u, al, mid, -1))
                    addQ(next_free, al, mid, bl, br);
                if (calc(u, mid+1, ar, -2))
                    addQ(next_free, mid+1, ar, bl, br);
            }   
            else{
                //place -1,-2
                s[u][al] = -1;
                s[u][ar] = -2;
            }
        }
        else{
            //check B
            s[u][0] = 1;
            if (range_b > 2){
                mid = (bl + br) / 2;
                if (calc(u, bl, mid,-2))
                    addQ(next_free, al, ar, bl, mid);
                if (calc(u, mid+1, br, -1))
                    addQ(next_free, al, ar, mid+1, br);
            }   
            else{
                //place -1,-2
                s[u][bl] = -2;
                s[u][br] = -1;
            }
        }
    }

    // printVct2D(s, "s");
    return s;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...