답안 #103782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103782 2019-04-02T15:22:03 Z alexpetrescu 최후의 만찬 (IOI12_supper) C++14
91 / 100
2500 ms 6912 KB
#include "advisor.h"
#include <vector>
#include <cstdio>

#define MAXN 100009

int heap[MAXN], poz[MAXN], d[MAXN];

inline void mySwap(int p, int q) {
    int aux = heap[p];
    heap[p] = heap[q];
    heap[q] = aux;
    poz[heap[p]] = p;
    poz[heap[q]] = q;
}

inline void urcare(int p) {
    while (p > 1 && d[heap[p]] > d[heap[p / 2]]) {
        mySwap(p, p / 2);
        p /= 2;
    }
}

inline void coborare(int p) {
    int q;
    bool f = 1;
    while (f && (q = 2 * p) <= heap[0]) {
        if (q < heap[0] && d[heap[q + 1]] > d[heap[q]])
            q++;
        if (d[heap[q]] > d[heap[p]]) {
            mySwap(p, q);
            p = q;
        } else
            f = 0;
    }
}

void ComputeAdvice(int *C, int N, int K, int M) {
    for (int i = 0; i < N; i++)
        d[i] = N;
    for (int i = 0; i < N; i++)
        if (d[C[i]] == N)
            d[C[i]] = i;

    for (int i = 0; i < K; i++)
        heap[++heap[0]] = i, poz[i] = i + 1;
    for (int i = heap[0]; i > 0; i--)
        coborare(i);

    std::vector < int > urm(N), last(N, N);
    for (int i = N - 1; i >= 0; i--) {
        urm[i] = last[C[i]];
        last[C[i]] = i;
    }

    std::vector < bool > ans(N + K, 1);
    std::vector < int > moment(N, -1);
    for (int i = 0; i < K; i++)
        moment[i] = i;

    for (int i = 0; i < N; i++) {
        if (poz[C[i]]) {
            d[C[i]] = urm[i];
            urcare(poz[C[i]]);
        } else {
            ans[moment[heap[1]]] = 0;
            poz[heap[1]] = 0;
            heap[1] = C[i];
            poz[C[i]] = 1;
            d[heap[1]] = urm[i];
            coborare(1);
        }
        moment[C[i]] = i + K;
    }

    for (int i = 0; i < N + K; i++)
        WriteAdvice(ans[i]);
}
#include "assistant.h"
#include <vector>

void Assist(unsigned char *A, int N, int K, int R) {
    std::vector < int > v(K), t(N, 0);
    for (int i = 0; i < K; i++)
        v[i] = i, t[i] = A[i];
    for (int i = 0; i < N; i++) {
        int x = GetRequest();
        int p = 0;
        while (p < K && v[p] != x)
            p++;
        if (p >= K) {
            p = 0;
            while (t[v[p]])
                p++;
            PutBack(v[p]);
            v[p] = x;
        }
        t[x] = A[i + K];
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 4 ms 772 KB Output is correct
4 Correct 7 ms 968 KB Output is correct
5 Correct 7 ms 1024 KB Output is correct
6 Correct 9 ms 1080 KB Output is correct
7 Correct 10 ms 1148 KB Output is correct
8 Correct 9 ms 1072 KB Output is correct
9 Correct 11 ms 1140 KB Output is correct
10 Correct 12 ms 1124 KB Output is correct
11 Correct 10 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1536 KB Output is correct
2 Correct 225 ms 3840 KB Output is correct
3 Execution timed out 2545 ms 6896 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1030 ms 4864 KB Output is correct
2 Correct 1573 ms 6896 KB Output is correct
3 Correct 1514 ms 6896 KB Output is correct
4 Correct 1398 ms 6912 KB Output is correct
5 Correct 1089 ms 6896 KB Output is correct
6 Correct 1424 ms 6896 KB Output is correct
7 Correct 1520 ms 6896 KB Output is correct
8 Correct 1905 ms 6896 KB Output is correct
9 Correct 1309 ms 6896 KB Output is correct
10 Correct 1592 ms 6896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1060 KB Output is correct
2 Correct 12 ms 1144 KB Output is correct
3 Correct 8 ms 1172 KB Output is correct
4 Correct 7 ms 1164 KB Output is correct
5 Correct 8 ms 1164 KB Output is correct
6 Correct 10 ms 1072 KB Output is correct
7 Correct 8 ms 1080 KB Output is correct
8 Correct 12 ms 1072 KB Output is correct
9 Correct 11 ms 1172 KB Output is correct
10 Correct 13 ms 1088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1329 ms 5632 KB Output is correct - 120000 bits used
2 Correct 1377 ms 5888 KB Output is correct - 122000 bits used
3 Correct 1317 ms 5872 KB Output is correct - 125000 bits used
4 Correct 1583 ms 5872 KB Output is correct - 125000 bits used
5 Correct 1514 ms 5744 KB Output is correct - 125000 bits used
6 Correct 1582 ms 5872 KB Output is correct - 125000 bits used
7 Correct 1485 ms 5872 KB Output is correct - 124828 bits used
8 Correct 1492 ms 5744 KB Output is correct - 124910 bits used
9 Correct 1428 ms 5872 KB Output is correct - 125000 bits used
10 Correct 1700 ms 5888 KB Output is correct - 125000 bits used