답안 #718892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718892 2023-04-05T05:04:59 Z lam 최후의 만찬 (IOI12_supper) C++14
100 / 100
168 ms 14956 KB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
#define ff first
#define ss second
const int maxn = 2e5 + 10;
map<int,int> mp;
int a[maxn],pre[maxn],id[maxn],type[maxn];
int xoa[maxn];
void ComputeAdvice(int *C, int N, int K, int M) {
int n,k,m;
    n=N; k=K;
    for (int i=1; i<=k; i++) a[i]=i-1;
    for (int i=1; i<=n; i++) a[i+k] = C[i-1];
    mp.clear();
    m=n+k;
    for (int i=m; i>=1; i--)
    {
        if (!mp[a[i]]) pre[i]=m+1;
        else pre[i]=mp[a[i]];
        mp[a[i]]=i;
    }
    fill_n(id,m+1,0);
    fill_n(type,m+1,0);
    multiset<ii> ms;
    for (int i=1; i<=k; i++) ms.insert({pre[i],i}),id[a[i]]=i;
    int num=0;
    for (int i=k+1; i<=m; i++)
    {
        if (id[a[i]]!=0)
        {
            int x=id[a[i]];
            ms.erase(ms.find({pre[x],x}));
            type[x] = 1;
            id[a[i]]=i;
            ms.insert({pre[i],i});
            continue;
        }
        auto it = ms.end(); it--;
        xoa[i] = it->ss;
        ms.erase(it);
        ms.insert({pre[i],i});
        type[xoa[i]] = 2;
        id[a[xoa[i]]] = 0;
        id[a[i]] = i;
        num++;
    }
//    cerr<<num<<"!!"<<endl;
    for (int i=0; i<n; i++) if (id[i]!=0) type[id[i]] = 2;
    for (int i=1; i<=m; i++) if (type[i]==2) WriteAdvice(1);
    else WriteAdvice(0);
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
typedef pair<int,int> ii;
#define ff first
#define ss second
int n,m,k;
int type[maxn];
void Assist(unsigned char *A, int N, int K, int R) {

    n=N;
    k=K;
    m=n+k;
    multiset<ii> ms;
    fill_n(type,m+1,0);
    for (int i=1; i<=k; i++)
    {
        char x = A[i-1];
        if (x==1) type[i-1] = 2;
        else type[i-1] = 1;
        ms.insert({type[i-1],i-1});
    }
    for (int i=1; i<=n; i++)
    {
        int x=GetRequest();
        char c = A[k+i-1];
        if (type[x]!=0)
        {
            ms.erase(ms.find({type[x],x}));
            int last = type[x];
            type[x] = (c==1)+1;
            ms.insert({type[x],x});
        }
        else
        {
            auto r = ms.end(); r--;
            PutBack(r->ss);
            type[r->ss] = 0;
            ms.erase(r);
            type[x] = (c==1)+1;
            ms.insert({type[x],x});
        }
    }

}

Compilation message

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:32:17: warning: unused variable 'last' [-Wunused-variable]
   32 |             int last = type[x];
      |                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 516 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Correct 2 ms 872 KB Output is correct
4 Correct 4 ms 800 KB Output is correct
5 Correct 5 ms 1212 KB Output is correct
6 Correct 6 ms 1140 KB Output is correct
7 Correct 7 ms 1036 KB Output is correct
8 Correct 6 ms 1216 KB Output is correct
9 Correct 6 ms 1132 KB Output is correct
10 Correct 7 ms 1216 KB Output is correct
11 Correct 6 ms 1220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1748 KB Output is correct
2 Correct 69 ms 5032 KB Output is correct
3 Correct 144 ms 14956 KB Output is correct
4 Correct 91 ms 9620 KB Output is correct
5 Correct 92 ms 9824 KB Output is correct
6 Correct 109 ms 10464 KB Output is correct
7 Correct 142 ms 12392 KB Output is correct
8 Correct 116 ms 12704 KB Output is correct
9 Correct 80 ms 6904 KB Output is correct
10 Correct 152 ms 13764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 9620 KB Output is correct
2 Correct 143 ms 12980 KB Output is correct
3 Correct 150 ms 13228 KB Output is correct
4 Correct 168 ms 12808 KB Output is correct
5 Correct 143 ms 11464 KB Output is correct
6 Correct 150 ms 13004 KB Output is correct
7 Correct 149 ms 12940 KB Output is correct
8 Correct 138 ms 14308 KB Output is correct
9 Correct 141 ms 11672 KB Output is correct
10 Correct 156 ms 13096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1096 KB Output is correct
2 Correct 7 ms 1196 KB Output is correct
3 Correct 5 ms 956 KB Output is correct
4 Correct 7 ms 1080 KB Output is correct
5 Correct 5 ms 1084 KB Output is correct
6 Correct 4 ms 1068 KB Output is correct
7 Correct 6 ms 1092 KB Output is correct
8 Correct 7 ms 1212 KB Output is correct
9 Correct 8 ms 1220 KB Output is correct
10 Correct 9 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 11276 KB Output is correct - 120000 bits used
2 Correct 150 ms 11516 KB Output is correct - 122000 bits used
3 Correct 147 ms 11988 KB Output is correct - 125000 bits used
4 Correct 148 ms 11896 KB Output is correct - 125000 bits used
5 Correct 150 ms 11876 KB Output is correct - 125000 bits used
6 Correct 147 ms 11956 KB Output is correct - 125000 bits used
7 Correct 157 ms 11868 KB Output is correct - 124828 bits used
8 Correct 144 ms 11812 KB Output is correct - 124910 bits used
9 Correct 163 ms 11952 KB Output is correct - 125000 bits used
10 Correct 133 ms 13212 KB Output is correct - 125000 bits used