Submission #968528

# Submission time Handle Problem Language Result Execution time Memory
968528 2024-04-23T14:37:30 Z steveonalex Last supper (IOI12_supper) C++17
100 / 100
113 ms 15056 KB
#include <bits/stdc++.h>
#include "advisor.h"
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }
 
void ComputeAdvice(int *C, int n, int k, int m){
    vector<vector<int>> color(n);
    for(int i = 0; i<n; ++i) color[C[i]].push_back(i);
    for(int i = 0; i<n; ++i) color[i].push_back(n);
    set<pair<int, int>> S;
    for(int i = 0; i<k; ++i) S.insert({color[i][0], i});
 
    vector<int> oo;
    for(int i = 0; i<n; ++i){
        auto it = S.begin();
        if ((*it).first == i){
            pair<int, int> y = *it;
            S.erase(it);
            S.insert({*upper_bound(ALL(color[C[i]]), i), y.second});
            oo.push_back(y.second);
        }
        else{
            auto it = S.rbegin();
            pair<int, int> y = *it;
            S.erase(y);
            oo.push_back(y.second);
            S.insert({*upper_bound(ALL(color[C[i]]), i), y.second});
        }
    }

    vector<int> nxt(k, n-1);
    vector<int> info;
    for(int i = n-1; i>=0; --i) {
        int cnt = upper_bound(ALL(color[C[i]]), nxt[oo[i]]) - upper_bound(ALL(color[C[i]]), i);
        info.push_back(cnt > 0);
        nxt[oo[i]] = i;
    }

    for(int i = k-1; i>=0; --i){
        int cnt = upper_bound(ALL(color[i]), nxt[i]) - lower_bound(ALL(color[i]), 0);
        info.push_back(cnt > 0);
    }
    reverse(ALL(info));

    for(int i: info) WriteAdvice(i);
 
    // const int LOG_N = logOf(k * 2);
    // for(int i: oo){
    //     for(int j = 0; j < LOG_N; ++j){
    //         WriteAdvice(i % 2);
    //         i /= 2;
    //     }
    // }
}
 
// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
//     int C[] = {2, 0, 3, 0};
 
//     ComputeAdvice(C, 4, 2, 1000);
 
//     return 0;
// }
#include <bits/stdc++.h>
#include "assistant.h"
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }
 
void Assist(unsigned char *A, int n, int k, int r){
    vector<int> state(k);
    for(int i = 0; i<k; ++i) state[i] = A[i];

    set<int> replacable;
    for(int i = 0; i<k; ++i) if (state[i] == 0) replacable.insert(i);

    vector<int> info;
    for(int i = k; i<r; ++i) info.push_back(A[i]);
    reverse(ALL(info));
 
    vector<int> scaffold(k);
    vector<int> S(n, -1);
    for(int i= 0; i<k; ++i) {
        scaffold[i] = i;
        S[i] = i;
    }


 
    for(int i = 0; i<n; ++i){
        int j = GetRequest();
        if (S[j] == -1){
            if (replacable.empty()) exit(1);
            int k = *replacable.begin();
            replacable.erase(k);

            PutBack(scaffold[k]);
            S[scaffold[k]] = -1;
            scaffold[k] = j;
            S[scaffold[k]] = k;

            state[k] = info.back(); info.pop_back();
            if (state[k] == 0) replacable.insert(k);
        }
        else{
            int k = S[j];
            replacable.erase(k);
            state[k] = info.back(); info.pop_back();
            if (state[k] == 0) replacable.insert(k);
        }
    }
}
// void PutBack(int T);
// int GetRequest();
 
 
// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 788 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 2 ms 796 KB Output is correct
4 Correct 3 ms 1068 KB Output is correct
5 Correct 3 ms 1360 KB Output is correct
6 Correct 4 ms 1356 KB Output is correct
7 Correct 4 ms 1352 KB Output is correct
8 Correct 4 ms 1356 KB Output is correct
9 Correct 4 ms 1360 KB Output is correct
10 Correct 5 ms 1624 KB Output is correct
11 Correct 4 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1896 KB Output is correct
2 Correct 40 ms 6608 KB Output is correct
3 Correct 94 ms 15056 KB Output is correct
4 Correct 63 ms 11020 KB Output is correct
5 Correct 66 ms 11060 KB Output is correct
6 Correct 80 ms 11780 KB Output is correct
7 Correct 89 ms 13104 KB Output is correct
8 Correct 73 ms 12220 KB Output is correct
9 Correct 61 ms 11512 KB Output is correct
10 Correct 107 ms 14256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 10196 KB Output is correct
2 Correct 94 ms 12516 KB Output is correct
3 Correct 95 ms 12528 KB Output is correct
4 Correct 97 ms 12552 KB Output is correct
5 Correct 92 ms 12228 KB Output is correct
6 Correct 97 ms 13684 KB Output is correct
7 Correct 113 ms 13792 KB Output is correct
8 Correct 83 ms 13632 KB Output is correct
9 Correct 77 ms 14100 KB Output is correct
10 Correct 96 ms 13704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1076 KB Output is correct
2 Correct 4 ms 1336 KB Output is correct
3 Correct 3 ms 1328 KB Output is correct
4 Correct 3 ms 1348 KB Output is correct
5 Correct 4 ms 1356 KB Output is correct
6 Correct 4 ms 1360 KB Output is correct
7 Correct 4 ms 1368 KB Output is correct
8 Correct 5 ms 1360 KB Output is correct
9 Correct 5 ms 1364 KB Output is correct
10 Correct 6 ms 1852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 11988 KB Output is correct - 120000 bits used
2 Correct 92 ms 12352 KB Output is correct - 122000 bits used
3 Correct 95 ms 12532 KB Output is correct - 125000 bits used
4 Correct 98 ms 12624 KB Output is correct - 125000 bits used
5 Correct 96 ms 12524 KB Output is correct - 125000 bits used
6 Correct 104 ms 12752 KB Output is correct - 125000 bits used
7 Correct 96 ms 12532 KB Output is correct - 124828 bits used
8 Correct 95 ms 12564 KB Output is correct - 124910 bits used
9 Correct 98 ms 12524 KB Output is correct - 125000 bits used
10 Correct 83 ms 12884 KB Output is correct - 125000 bits used