답안 #287313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287313 2020-08-31T15:20:22 Z stoyan_malinin 최후의 만찬 (IOI12_supper) C++14
0 / 100
608 ms 36604 KB
#include "advisor.h"

#include <set>
#include <map>
#include <queue>
#include <vector>
#include <iostream>

using namespace std;

namespace Advisor
{
    const int MAXN = 1e5 + 5;
    int maxLog;

    int nxtSame[MAXN], firstSeen[MAXN];
    vector <int> numSeq[MAXN];

    void init(int n, int *a, int k)
    {
        for(int i = 0;i<k;i++)
        {
            for(int bit = 0;bit<=maxLog;bit++)
                numSeq[i].push_back(((i>>bit)&1));
        }

        map <int, int> last;
        for(int i = 0;i<n;i++)
        {
            last[i] = n;
            firstSeen[i] = n;
        }
        for(int i = n-1;i>=0;i--)
        {
            nxtSame[i] = last[ a[i] ];
            last[ a[i] ] = i;

            firstSeen[ a[i] ] = i;
        }
    }

    int calcLog(int x)
    {
        int ans = 0;
        while(x!=1) x /= 2, ans++;

        return ans;
    }

    template <class T>
    T getLast(set <T> &s)
    {
        auto it = s.end();

        it--;
        return *it;
    }

};

void ComputeAdvice(int *C, int N, int K, int M)
{
    using namespace Advisor;
    maxLog = calcLog(K);
    init(N, C, K);

    set <pair <int, int>> s;
    map <int, int> colorPos, scaffold;

    for(int i = 0;i<N;i++)
    {
        colorPos[i] = -1;
    }
    for(int i = 0;i<K;i++)
    {
        scaffold[i] = i;
        colorPos[i] = i;
        s.insert({firstSeen[i], i});
    }

    for(int i = 0;i<N;i++)
    {
        //cout << " --- " << i << " --- " << '\n';

        if(colorPos[ C[i] ]!=-1)
        {
            s.erase({i, C[i]});
            s.insert({nxtSame[i], C[i]});

            continue;
        }

        //for(pair <int, int> item: s) cout << item.first << " " << item.second << " || ";
        //cout << '\n';

        pair <int, int> best = getLast(s);
        s.erase(best);

        //cout << best.first << " " << best.second << " -> " << scaffold[ best.second ] << '\n';

        colorPos[ scaffold[best.second] ] = -1;
        scaffold[best.second] = C[i];
        colorPos[ C[i] ] = best.second;

        for(int bit: numSeq[best.second]) WriteAdvice(bit);
        s.insert({nxtSame[i], best.second});
    }
}
#include "assistant.h"

#include <set>
#include <queue>
#include <vector>
#include <iostream>

using namespace std;

namespace Assitant
{
    const int MAXN = 1e5 + 5;
    int maxLog;

    int calcLog(int x)
    {
        int ans = 0;
        while(x!=1) x /= 2, ans++;

        return ans;
    }

    struct Reader
    {
        queue <int> q;

        Reader(){}
        Reader(int n, unsigned char *a)
        {
            for(int i = 0;i<n;i++)
                this->q.push(int(a[i]));
        }

        int readInt(int log2)
        {
            int x = 0;
            for(int bit = 0;bit<=log2;bit++)
            {
                int d = q.front();
                q.pop();

                x += (d<<bit);
            }

            return x;
        }
    };
};

void Assist(unsigned char *A, int N, int K, int R)
{
    using namespace Assitant;
    maxLog = calcLog(K);

    Reader yoanko(R, A);

    set <int> active;
    vector <int> scaffold(K);

    for(int i = 0;i<K;i++)
    {
        active.insert(i);
        scaffold[i] = i;
    }

    for(int iter = 0;iter<N;iter++)
    {
        int col = GetRequest();
        if(active.count(col)==true) continue;

        int pos = yoanko.readInt(maxLog);
        PutBack(scaffold[pos]);

        active.erase(scaffold[pos]);
        scaffold[pos] = col;
        active.insert(scaffold[pos]);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5376 KB Output is correct
2 Incorrect 3 ms 5376 KB Output isn't correct - not an optimal way
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 7920 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 365 ms 27216 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 6400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 440 ms 30960 KB Execution killed with signal 11
2 Runtime error 430 ms 31808 KB Execution killed with signal 11
3 Runtime error 420 ms 32584 KB Execution killed with signal 11
4 Runtime error 410 ms 32496 KB Execution killed with signal 11
5 Runtime error 432 ms 32496 KB Execution killed with signal 11
6 Runtime error 408 ms 32528 KB Execution killed with signal 11
7 Runtime error 427 ms 32456 KB Execution killed with signal 11
8 Runtime error 418 ms 32472 KB Execution killed with signal 11
9 Runtime error 409 ms 32824 KB Execution killed with signal 11
10 Runtime error 608 ms 36604 KB Execution killed with signal 11