답안 #365009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365009 2021-02-10T18:09:33 Z qwerasdfzxcl 최후의 만찬 (IOI12_supper) C++14
0 / 100
143 ms 14096 KB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> idx[100100];
int pt[100100], btpos[50050], bg[50050], bt[200200], bgidx[100100];
int tree[200200];

void ComputeAdvice(int *C, int N, int K, int M);
void WriteAdvice(unsigned char a);

int mx(int a, int b){
    if (idx[pt[bg[a]]]>idx[pt[bg[b]]]) return a;
    return b;
}

void build(int k){
    for (int i=k;i<2*k;i++) tree[i]=i-k;
    for (int i=k-1;i>0;i--) tree[i]=mx(tree[i<<1], tree[i<<1|1]);
}

void update(int p, int k){
    for (p += k;p>1;p>>=1) tree[p>>1]=mx(tree[p], tree[p^1]);
}

void ComputeAdvice(int *C, int N, int K, int M){
    for (int i=0;i<N;i++){
        idx[C[i]].push_back(i);
    }
    for (int i=0;i<N;i++) idx[i].push_back(1e9);
    for (int i=0;i<N;i++){
        bgidx[i]=-1;
    }
    for (int i=0;i<K;i++){
        bg[i]=i;
        bgidx[i]=i;
        btpos[i]=i;
    }
    build(K);
    for (int i=0;i<N;i++){
        if (bgidx[C[i]]!=-1){
            int tmp=bgidx[C[i]];
            bt[btpos[tmp]]=0;
            btpos[tmp]=N+i;
            pt[C[i]]++;
            update(tmp, K);
        }
        else{
            int tmp=tree[1];
            bt[btpos[tmp]]=1;
            btpos[tmp]=N+i;
            pt[C[i]]++;
            bgidx[bg[tmp]]=-1;
            bgidx[C[i]]=tmp;
            bg[tmp]=C[i];
            update(tmp, K);
        }
    }
    for (int i=0;i<N+K;i++){
        if (bt[i]==0) WriteAdvice(0);
        else WriteAdvice(1);
    }
}


/*#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int bg[100100];
int bgyes[100100];

void Assist(unsigned char *A, int N, int K, int R);
void PutBack(int T);
int GetRequest();

void Assist(unsigned char *A, int N, int K, int R){
    fill(bgyes, bgyes+N, -1);
    for (int i=0;i<K;i++){
        if (A[i]) q.push(i);
        bgyes[i]=i;
        bg[i]=i;
    }
    for (int i=0;i<N;i++){
        int tmp=GetRequest();
        if (bgyes[tmp]!=-1){
            if(A[N+i]) q.push(bgyes[tmp]);
            continue;
        }
        int idx=q.front();
        q.pop();
        PutBack(bg[idx]);
        bgyes[bg[idx]]=-1;
        bgyes[tmp]=idx;
        bg[idx]=tmp;
    }
}
*/
/*#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> idx[100100];
int pt[100100], btpos[50050], bg[50050], bt[200200], bgidx[100100];
int tree[200200];

void ComputeAdvice(int *C, int N, int K, int M);
void WriteAdvice(unsigned char a);

int mx(int a, int b){
    if (idx[pt[bg[a]]]>idx[pt[bg[b]]]) return a;
    return b;
}

void build(int k){
    for (int i=k;i<2*k;i++) tree[i]=i-k;
    for (int i=k-1;i>0;i--) tree[i]=mx(tree[i<<1], tree[i<<1|1]);
}

void update(int p, int k){
    for (p += k;p>1;p>>=1) tree[p>>1]=mx(tree[p], tree[p^1]);
}

void ComputeAdvice(int *C, int N, int K, int M){
    for (int i=0;i<N;i++){
        idx[C[i]].push_back(i);
    }
    for (int i=0;i<N;i++) idx[i].push_back(1e9);
    for (int i=0;i<N;i++){
        bgidx[i]=-1;
    }
    for (int i=0;i<K;i++){
        bg[i]=i;
        bgidx[i]=i;
        btpos[i]=i;
    }
    build(K);
    for (int i=0;i<N;i++){
        if (bgidx[C[i]]!=-1){
            int tmp=bgidx[C[i]];
            bt[btpos[tmp]]=0;
            btpos[tmp]=N+i;
            pt[C[i]]++;
            update(tmp, K);
        }
        else{
            int tmp=tree[1];
            bt[btpos[tmp]]=1;
            btpos[tmp]=N+i;
            pt[C[i]]++;
            bgidx[bg[tmp]]=-1;
            bgidx[C[i]]=tmp;
            bg[tmp]=C[i];
            update(tmp, K);
        }
    }
    for (int i=0;i<N+K;i++){
        if (bt[i]==0) WriteAdvice(0);
        else WriteAdvice(1);
    }
}*/


#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int bg[100100];
int bgyes[100100];

void Assist(unsigned char *A, int N, int K, int R);
void PutBack(int T);
int GetRequest();

void Assist(unsigned char *A, int N, int K, int R){
    fill(bgyes, bgyes+N, -1);
    for (int i=0;i<K;i++){
        if (A[i]) q.push(i);
        bgyes[i]=i;
        bg[i]=i;
    }
    for (int i=0;i<N;i++){
        int tmp=GetRequest();
        if (bgyes[tmp]!=-1){
            if(A[N+i]) q.push(bgyes[tmp]);
            continue;
        }
        int idx=q.front();
        q.pop();
        PutBack(bg[idx]);
        bgyes[bg[idx]]=-1;
        bgyes[tmp]=idx;
        bg[idx]=tmp;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3204 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 4188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 97 ms 11876 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3736 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 118 ms 13544 KB Execution killed with signal 11
2 Runtime error 110 ms 13816 KB Execution killed with signal 6
3 Runtime error 113 ms 13752 KB Execution killed with signal 11
4 Runtime error 122 ms 14076 KB Execution killed with signal 11
5 Runtime error 112 ms 13768 KB Execution killed with signal 11
6 Runtime error 143 ms 14008 KB Execution killed with signal 11
7 Runtime error 136 ms 13804 KB Execution killed with signal 11
8 Runtime error 112 ms 13892 KB Execution killed with signal 11
9 Runtime error 121 ms 14096 KB Execution killed with signal 11
10 Runtime error 116 ms 13652 KB Execution killed with signal 11