답안 #365017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365017 2021-02-10T18:25:45 Z qwerasdfzxcl 최후의 만찬 (IOI12_supper) C++14
0 / 100
136 ms 12860 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[bg[a]][pt[bg[a]]]>idx[bg[b]][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[bg[a]][pt[bg[a]]]>idx[bg[b]][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 2 ms 3204 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 4188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 97 ms 11540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 122 ms 12340 KB Execution killed with signal 11
2 Runtime error 133 ms 12572 KB Execution killed with signal 11
3 Runtime error 124 ms 12860 KB Execution killed with signal 11
4 Runtime error 121 ms 12604 KB Execution killed with signal 11
5 Runtime error 120 ms 12604 KB Execution killed with signal 11
6 Runtime error 122 ms 12604 KB Execution killed with signal 11
7 Runtime error 136 ms 12852 KB Execution killed with signal 11
8 Runtime error 121 ms 12848 KB Execution killed with signal 11
9 Runtime error 130 ms 12856 KB Execution killed with signal 11
10 Runtime error 119 ms 12472 KB Execution killed with signal 11