Submission #753876

# Submission time Handle Problem Language Result Execution time Memory
753876 2023-06-06T08:48:32 Z marvinthang Last supper (IOI12_supper) C++17
100 / 100
97 ms 7040 KB
/*************************************
*    author: marvinthang             *
*    created: 04.06.2023 19:41:31    *
*************************************/

#include "advisor.h"
#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i--; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

void ComputeAdvice(int *C, int N, int K, int M) {
    vector <int> nxt(N), last(N, N), pos(N, -1);
    REPD(i, N) {
        nxt[i] = last[C[i]];
        last[C[i]] = i;
    }
    set <pair <int, int>> s;
    REP(i, K) {
        s.insert(make_pair(-last[i], i));
        last[i] = i;
        pos[i] = i;
    }
    vector <int> put(N + K);
    REP(i, N) {
        if (pos[C[i]] != -1) s.erase(make_pair(-i, C[i]));
        else {
            int x = s.begin()->se;
            pos[C[i]] = pos[x];
            put[last[x]] = true;
            pos[x] = -1;
            s.erase(s.begin());
        }
        last[C[i]] = i + K;
        s.insert(make_pair(-nxt[i], C[i]));
    }
    for (int x: put) WriteAdvice(x);
}
/*************************************
*    author: marvinthang             *
*    created: 04.06.2023 20:07:48    *
*************************************/

#include "assistant.h"
#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i--; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

void Assist(unsigned char *A, int N, int K, int R) {
    vector <int> pos(N, -1), col(K);
    vector <int> put;
    REP(i, K) {
        col[i] = pos[i] = i;
        if (A[i]) put.push_back(i);
    }
    int cur = 0;
    REP(i, N) {
        int x = GetRequest();
        if (pos[x] != -1) {
            if (A[i + K]) put.push_back(x);
            continue;
        }
        assert(!put.empty());
        int v = put.back(); put.pop_back();
        PutBack(v);
        v = pos[v];
        pos[col[v]] = -1;
        col[v] = x;
        pos[x] = v;
        if (A[i + K]) put.push_back(x);
    }
}

Compilation message

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:53:9: warning: unused variable 'cur' [-Wunused-variable]
   53 |     int cur = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 520 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 3 ms 668 KB Output is correct
5 Correct 3 ms 828 KB Output is correct
6 Correct 4 ms 920 KB Output is correct
7 Correct 5 ms 904 KB Output is correct
8 Correct 4 ms 956 KB Output is correct
9 Correct 4 ms 948 KB Output is correct
10 Correct 4 ms 1068 KB Output is correct
11 Correct 5 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1276 KB Output is correct
2 Correct 35 ms 3232 KB Output is correct
3 Correct 87 ms 7040 KB Output is correct
4 Correct 53 ms 4992 KB Output is correct
5 Correct 69 ms 5044 KB Output is correct
6 Correct 65 ms 5260 KB Output is correct
7 Correct 94 ms 6052 KB Output is correct
8 Correct 72 ms 5724 KB Output is correct
9 Correct 49 ms 5036 KB Output is correct
10 Correct 86 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 5320 KB Output is correct
2 Correct 88 ms 6432 KB Output is correct
3 Correct 94 ms 6492 KB Output is correct
4 Correct 92 ms 6516 KB Output is correct
5 Correct 83 ms 6060 KB Output is correct
6 Correct 82 ms 6768 KB Output is correct
7 Correct 88 ms 6692 KB Output is correct
8 Correct 73 ms 6488 KB Output is correct
9 Correct 79 ms 6604 KB Output is correct
10 Correct 82 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 952 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 6 ms 956 KB Output is correct
4 Correct 4 ms 928 KB Output is correct
5 Correct 4 ms 816 KB Output is correct
6 Correct 4 ms 956 KB Output is correct
7 Correct 4 ms 956 KB Output is correct
8 Correct 5 ms 928 KB Output is correct
9 Correct 5 ms 948 KB Output is correct
10 Correct 6 ms 1092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 6232 KB Output is correct - 120000 bits used
2 Correct 97 ms 6108 KB Output is correct - 122000 bits used
3 Correct 82 ms 6320 KB Output is correct - 125000 bits used
4 Correct 82 ms 6404 KB Output is correct - 125000 bits used
5 Correct 81 ms 6488 KB Output is correct - 125000 bits used
6 Correct 81 ms 6464 KB Output is correct - 125000 bits used
7 Correct 87 ms 6452 KB Output is correct - 124828 bits used
8 Correct 82 ms 6408 KB Output is correct - 124910 bits used
9 Correct 89 ms 6360 KB Output is correct - 125000 bits used
10 Correct 77 ms 6280 KB Output is correct - 125000 bits used