Submission #597824

# Submission time Handle Problem Language Result Execution time Memory
597824 2022-07-17T00:56:20 Z skittles1412 Last supper (IOI12_supper) C++17
43 / 100
263 ms 17952 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) {
    int bits = __lg(k - 1) + 1;
    dbg(bits);
    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);
    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) {
            pq.erase({cx, arr[i]});
            pq.emplace(inds[arr[i]].back(), arr[i]);
            continue;
        }
        int x = (--pq.end())->second;
        pq.erase(--pq.end());
        write(bits, in[x]);
        swap(in[x], in[arr[i]]);
        pq.emplace(inds[arr[i]].back(), arr[i]);
        ans++;
    }
    dbg(ans);
}
#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) {
    int bits = __lg(k - 1) + 1;
    int vals[k], inds[n];
    iota(vals, vals + k, 0);
    memset(inds, -1, sizeof(inds));
    iota(inds, inds + k, 0);
    for (int i = 0; i < n; i++) {
        int cur = GetRequest();
        if (inds[cur] != -1) {
            continue;
        }
        int x = read(buf, bits);
        assert(inds[vals[x]] == x);
        PutBack(vals[x]);
        swap(inds[vals[x]], inds[cur]);
        vals[x] = cur;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 508 KB Output is correct
2 Correct 1 ms 520 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 3 ms 1056 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 4 ms 1072 KB Output is correct
8 Correct 11 ms 1284 KB Output is correct
9 Correct 10 ms 1276 KB Output is correct
10 Correct 7 ms 1220 KB Output is correct
11 Correct 11 ms 1248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1772 KB Output is correct
2 Correct 74 ms 7168 KB Output is correct
3 Correct 226 ms 17404 KB Output is correct
4 Correct 187 ms 13480 KB Output is correct
5 Correct 194 ms 15412 KB Output is correct
6 Correct 251 ms 15848 KB Output is correct
7 Correct 200 ms 15680 KB Output is correct
8 Correct 240 ms 15304 KB Output is correct
9 Correct 104 ms 12648 KB Output is correct
10 Correct 186 ms 15628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 11704 KB Output is correct
2 Correct 225 ms 15560 KB Output is correct
3 Correct 187 ms 15520 KB Output is correct
4 Correct 221 ms 15204 KB Output is correct
5 Correct 148 ms 13832 KB Output is correct
6 Correct 203 ms 15524 KB Output is correct
7 Correct 185 ms 15296 KB Output is correct
8 Correct 263 ms 17952 KB Output is correct
9 Correct 129 ms 13832 KB Output is correct
10 Correct 206 ms 15404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 900 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 214 ms 14504 KB Output is partially correct - 772365 bits used
2 Correct 209 ms 14452 KB Output is partially correct - 742095 bits used
3 Correct 221 ms 14372 KB Output is partially correct - 712470 bits used
4 Correct 194 ms 14460 KB Output is partially correct - 712005 bits used
5 Correct 213 ms 14412 KB Output is partially correct - 710610 bits used
6 Correct 196 ms 14444 KB Output is partially correct - 712155 bits used
7 Correct 234 ms 14288 KB Output is partially correct - 711090 bits used
8 Correct 232 ms 14284 KB Output is partially correct - 713340 bits used
9 Correct 212 ms 14368 KB Output is partially correct - 712830 bits used
10 Correct 252 ms 16692 KB Output is partially correct - 1117620 bits used