답안 #251313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251313 2020-07-20T17:31:43 Z eohomegrownapps 최후의 만찬 (IOI12_supper) C++14
61 / 100
354 ms 143600 KB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename V>
using pbds_map = tree<T, V, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void ComputeAdvice(int *c, int n, int k, int m) {
    vector<queue<int>> nextocc(n);
    for (int i = 0; i<n; i++){
        nextocc[c[i]].push(i);
    }
    int bitwidth = ceil(log2(k));
    set<pair<int,int>> scaffrem;
    pbds_set<int> scaff;
    for (int i = 0; i<k; i++){
        if (nextocc[i].size()>0){
            scaffrem.insert({nextocc[i].front(),i});
        } else {
            scaffrem.insert({n,i});
        }
        scaff.insert(i);
    }
    for (int i = 0; i<n; i++){
        //cout<<i<<'\n';
        if (scaff.find(c[i])!=scaff.end()){
            scaffrem.erase({nextocc[c[i]].front(),c[i]});
        } else {
            //check if the one we just put on can be removed
            auto toremove = prev(scaffrem.end());
            int ind;
            if (i>0&&nextocc[c[i-1]].size()==0&&c[i]!=c[i-1]){
                //cout<<"remove\n";
                WriteAdvice(1);
                toremove = scaffrem.find({n,c[i-1]});
                ind = scaff.order_of_key(toremove->second);
            } else {
                WriteAdvice(0);
                //cout<<"take\n";
                //can we get rid of one we've already used
                /*auto it = scaffrem.lower_bound({i,-1});
                if (it!=scaffrem.begin()){
                    toremove = prev(it);
                }*/
                //transmit ind
                ind = scaff.order_of_key(toremove->second);
                for (int i = bitwidth-1; i>=0; i--){
                    WriteAdvice(bool((1<<i)&ind));
                }
            }
            scaffrem.erase(toremove);
            scaff.erase(scaff.find_by_order(ind));
            scaff.insert(c[i]);
        }
        int newind = n;
        nextocc[c[i]].pop();
        if (nextocc[c[i]].size()>0){
            newind=nextocc[c[i]].front();
        }
        scaffrem.insert({newind,c[i]});
    }
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename V>
using pbds_map = tree<T, V, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void Assist(unsigned char *A, int n, int k, int r) {
    //GetRequest()
    //PutBack()
    int ptr = 0;
    int bitwidth = ceil(log2(k));
    pbds_set<int> scaff;
    for (int i = 0; i<k; i++){
        scaff.insert(i);
    }
    int prevcol = -1;
    for (int i = 0; i<n; i++){
        int col = GetRequest();
        if (scaff.find(col)!=scaff.end()){
            prevcol=col;
            continue;
        } else {
            int removeLast = A[ptr];
            //cout<<ptr<<" "<<int(A[ptr])<<'\n';
            ptr++;
            auto putel = scaff.begin();
            if (removeLast){
                putel = scaff.find(prevcol);
            } else {
                int ind = 0;
                for (int i = 0; i<bitwidth; i++){
                    ind*=2;
                    ind+=A[ptr];
                    ptr++;
                }
                //cout<<ind<<'\n';
                putel = scaff.find_by_order(ind);
            }
            //cout<<"put back "<<*putel<<'\n';
            PutBack(*putel);
            scaff.erase(putel);
            scaff.insert(col);
        }
        prevcol=col;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 772 KB Output is correct
2 Correct 1 ms 964 KB Output is correct
3 Correct 3 ms 2048 KB Output is correct
4 Correct 6 ms 4864 KB Output is correct
5 Correct 7 ms 7424 KB Output is correct
6 Correct 11 ms 7424 KB Output is correct
7 Correct 8 ms 7680 KB Output is correct
8 Correct 11 ms 7680 KB Output is correct
9 Correct 15 ms 7680 KB Output is correct
10 Correct 11 ms 7936 KB Output is correct
11 Correct 13 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 14592 KB Output is correct
2 Correct 145 ms 70424 KB Output is correct
3 Correct 353 ms 143600 KB Output is correct
4 Correct 222 ms 137200 KB Output is correct
5 Correct 291 ms 137352 KB Output is correct
6 Correct 343 ms 138752 KB Output is correct
7 Correct 329 ms 140784 KB Output is correct
8 Correct 258 ms 120816 KB Output is correct
9 Correct 215 ms 134896 KB Output is correct
10 Correct 349 ms 142832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 113648 KB Output is correct
2 Correct 354 ms 141808 KB Output is correct
3 Correct 341 ms 141816 KB Output is correct
4 Correct 331 ms 142064 KB Output is correct
5 Correct 314 ms 139640 KB Output is correct
6 Correct 330 ms 141808 KB Output is correct
7 Correct 336 ms 141808 KB Output is correct
8 Correct 306 ms 141296 KB Output is correct
9 Correct 291 ms 142064 KB Output is correct
10 Correct 332 ms 141808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6400 KB Output is correct
2 Correct 11 ms 7680 KB Output is correct
3 Incorrect 3 ms 7424 KB Error - advice is too long
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 328 ms 140528 KB Output is partially correct - 368771 bits used
2 Correct 335 ms 141296 KB Output is partially correct - 359913 bits used
3 Correct 331 ms 141552 KB Output is partially correct - 344933 bits used
4 Correct 347 ms 141552 KB Output is partially correct - 344437 bits used
5 Correct 349 ms 141536 KB Output is partially correct - 344434 bits used
6 Correct 349 ms 141296 KB Output is partially correct - 344552 bits used
7 Correct 329 ms 141296 KB Output is partially correct - 344586 bits used
8 Correct 346 ms 141488 KB Output is partially correct - 344286 bits used
9 Correct 335 ms 141296 KB Output is partially correct - 343832 bits used
10 Correct 309 ms 141040 KB Output is correct - 96843 bits used