Submission #430192

# Submission time Handle Problem Language Result Execution time Memory
430192 2021-06-16T12:00:36 Z wiwiho Last supper (IOI12_supper) C++14
100 / 100
254 ms 72656 KB
#include "advisor.h"

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

void ComputeAdvice(int *C, int n, int k, int M){

    vector<int> ans(k + n);

    vector<int> lst(n, -1);
    vector<queue<int>> pos(n);
    for(int i = 0; i < n; i++){
        pos[C[i]].push(k + i);
    }
    for(int i = 0; i < n; i++) pos[i].push(k + n);

    set<pii> st;
    for(int i = 0; i < k; i++){
        lst[i] = i;
        st.insert(mp(pos[i].front(), i));
    }

    for(int i = 0; i < n; i++){
        int c = C[i];
        if(lst[c] != -1){
            lst[c] = k + i;
            st.erase(mp(pos[c].front(), c));
            pos[c].pop();
            st.insert(mp(pos[c].front(), c));
            continue;
        }

        int r = st.rbegin()->S;
        st.erase(prev(st.end()));
        ans[lst[r]] = 1;
        lst[r] = -1;
        lst[c] = k + i;
        pos[c].pop();
        st.insert(mp(pos[c].front(), c));
    }

    for(int i : ans) WriteAdvice(i);

}
#include "assistant.h"

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

void Assist(unsigned char *A, int n, int k, int R) {

    set<int> q;
    vector<bool> ok(n);
    for(int i = 0; i < k; i++){
        if(A[i]) q.insert(i);
        ok[i] = true;
    }

    for(int i = k; i < k + n; i++){
        int c = GetRequest();
        q.erase(c);
        if(!ok[c]){
            int r = *q.begin();
            q.erase(r);
            PutBack(r);
            ok[r] = false;
            ok[c] = true;
        }
        if(A[i]) q.insert(c);
    }

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 484 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 3 ms 1260 KB Output is correct
4 Correct 4 ms 2580 KB Output is correct
5 Correct 8 ms 4016 KB Output is correct
6 Correct 7 ms 4016 KB Output is correct
7 Correct 10 ms 4140 KB Output is correct
8 Correct 8 ms 4140 KB Output is correct
9 Correct 7 ms 4116 KB Output is correct
10 Correct 8 ms 4248 KB Output is correct
11 Correct 8 ms 4116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 7744 KB Output is correct
2 Correct 96 ms 36244 KB Output is correct
3 Correct 212 ms 72652 KB Output is correct
4 Correct 168 ms 70424 KB Output is correct
5 Correct 181 ms 70532 KB Output is correct
6 Correct 200 ms 70836 KB Output is correct
7 Correct 204 ms 71868 KB Output is correct
8 Correct 181 ms 61184 KB Output is correct
9 Correct 139 ms 69296 KB Output is correct
10 Correct 252 ms 72424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 58040 KB Output is correct
2 Correct 214 ms 72216 KB Output is correct
3 Correct 227 ms 72304 KB Output is correct
4 Correct 218 ms 72200 KB Output is correct
5 Correct 204 ms 71520 KB Output is correct
6 Correct 249 ms 72184 KB Output is correct
7 Correct 243 ms 72268 KB Output is correct
8 Correct 208 ms 71844 KB Output is correct
9 Correct 225 ms 72656 KB Output is correct
10 Correct 228 ms 72132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3324 KB Output is correct
2 Correct 10 ms 4148 KB Output is correct
3 Correct 7 ms 4020 KB Output is correct
4 Correct 8 ms 4120 KB Output is correct
5 Correct 10 ms 4016 KB Output is correct
6 Correct 8 ms 4024 KB Output is correct
7 Correct 8 ms 4124 KB Output is correct
8 Correct 10 ms 4252 KB Output is correct
9 Correct 9 ms 4248 KB Output is correct
10 Correct 10 ms 4412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 71980 KB Output is correct - 120000 bits used
2 Correct 216 ms 71968 KB Output is correct - 122000 bits used
3 Correct 214 ms 72196 KB Output is correct - 125000 bits used
4 Correct 254 ms 72332 KB Output is correct - 125000 bits used
5 Correct 226 ms 72128 KB Output is correct - 125000 bits used
6 Correct 230 ms 72160 KB Output is correct - 125000 bits used
7 Correct 211 ms 72076 KB Output is correct - 124828 bits used
8 Correct 238 ms 72276 KB Output is correct - 124910 bits used
9 Correct 230 ms 72248 KB Output is correct - 125000 bits used
10 Correct 198 ms 71824 KB Output is correct - 125000 bits used