Submission #599465

# Submission time Handle Problem Language Result Execution time Memory
599465 2022-07-19T14:21:30 Z skittles1412 Last supper (IOI12_supper) C++17
100 / 100
185 ms 12696 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
    cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t << " | ";
    dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                              \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
    dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr   \
    if (false) \
    cerr
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

void WriteAdvice(unsigned char a);

void write(int bits, int x) {
    for (int i = 0; i < bits; i++) {
        WriteAdvice((x >> i) & 1);
    }
}

void ComputeAdvice(int* arr, int n, int k, int) {
    vector<int> inds[n];
    for (int i = 0; i < n; i++) {
        inds[arr[i]].push_back(i);
    }
    for (auto& a : inds) {
        a.push_back(n);
        reverse(begin(a), end(a));
    }
    int in[n];
    memset(in, -1, sizeof(in));
    iota(in, in + k, 0);
    bool vis[n + k] {};
    set<pair<int, int>> pq;
    for (int i = 0; i < k; i++) {
        pq.emplace(inds[i].back(), i);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int cx = inds[arr[i]].back();
        inds[arr[i]].pop_back();
        if (in[arr[i]] != -1) {
            vis[in[arr[i]]] = true;
            in[arr[i]] = i + k;
            pq.erase({cx, arr[i]});
            pq.emplace(inds[arr[i]].back(), arr[i]);
            continue;
        }
        int x = (--pq.end())->second;
        pq.erase(--pq.end());
        in[x] = -1;
        in[arr[i]] = i + k;
        pq.emplace(inds[arr[i]].back(), arr[i]);
        ans++;
    }
    for (auto& a : vis) {
        WriteAdvice(a);
    }
}
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
    cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t << " | ";
    dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                              \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
    dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr   \
    if (false) \
    cerr
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

int GetRequest();
void PutBack(int T);

int read(unsigned char*& ptr, int bits) {
    int x = 0;
    for (int i = 0; i < bits; i++) {
        x |= *(ptr++) << i;
    }
    return x;
}

void Assist(unsigned char* buf, int n, int k, int) {
    bool vis[n] {};
    vector<int> unused;
    for (int i = 0; i < k; i++) {
        vis[i] = true;
        if (!read(buf, 1)) {
            unused.push_back(i);
        }
    }
    for (int i = 0; i < n; i++) {
        int cur = GetRequest();
        if (!vis[cur]) {
            int u = unused.back();
            unused.pop_back();
            PutBack(u);
            vis[u] = false;
            vis[cur] = true;
        }
        if (!read(buf, 1)) {
            unused.push_back(cur);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 520 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 804 KB Output is correct
5 Correct 3 ms 948 KB Output is correct
6 Correct 4 ms 956 KB Output is correct
7 Correct 4 ms 1228 KB Output is correct
8 Correct 8 ms 1076 KB Output is correct
9 Correct 9 ms 976 KB Output is correct
10 Correct 8 ms 1176 KB Output is correct
11 Correct 5 ms 1212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1592 KB Output is correct
2 Correct 42 ms 5800 KB Output is correct
3 Correct 98 ms 12696 KB Output is correct
4 Correct 94 ms 10492 KB Output is correct
5 Correct 101 ms 10316 KB Output is correct
6 Correct 150 ms 10860 KB Output is correct
7 Correct 98 ms 11592 KB Output is correct
8 Correct 71 ms 10460 KB Output is correct
9 Correct 84 ms 10708 KB Output is correct
10 Correct 118 ms 12324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 9692 KB Output is correct
2 Correct 106 ms 11960 KB Output is correct
3 Correct 146 ms 11856 KB Output is correct
4 Correct 110 ms 12000 KB Output is correct
5 Correct 102 ms 11708 KB Output is correct
6 Correct 136 ms 12016 KB Output is correct
7 Correct 185 ms 11904 KB Output is correct
8 Correct 108 ms 11920 KB Output is correct
9 Correct 109 ms 12168 KB Output is correct
10 Correct 100 ms 12008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 908 KB Output is correct
2 Correct 7 ms 1184 KB Output is correct
3 Correct 3 ms 956 KB Output is correct
4 Correct 3 ms 948 KB Output is correct
5 Correct 4 ms 948 KB Output is correct
6 Correct 4 ms 956 KB Output is correct
7 Correct 6 ms 1052 KB Output is correct
8 Correct 6 ms 1080 KB Output is correct
9 Correct 8 ms 1212 KB Output is correct
10 Correct 7 ms 1288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 11640 KB Output is correct - 120000 bits used
2 Correct 123 ms 11876 KB Output is correct - 122000 bits used
3 Correct 98 ms 11988 KB Output is correct - 125000 bits used
4 Correct 100 ms 11904 KB Output is correct - 125000 bits used
5 Correct 98 ms 12140 KB Output is correct - 125000 bits used
6 Correct 126 ms 11980 KB Output is correct - 125000 bits used
7 Correct 139 ms 11920 KB Output is correct - 124828 bits used
8 Correct 107 ms 12064 KB Output is correct - 124910 bits used
9 Correct 117 ms 12028 KB Output is correct - 125000 bits used
10 Correct 130 ms 11928 KB Output is correct - 125000 bits used