Submission #288175

# Submission time Handle Problem Language Result Execution time Memory
288175 2020-09-01T09:34:41 Z erd1 Last supper (IOI12_supper) C++14
0 / 100
147 ms 8944 KB
#include "advisor.h"

#include<bits/stdc++.h>
using namespace std;

#include<bits/extc++.h>
using namespace __gnu_pbds;
template<typename T>
using order_statistics_tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//#define int lld
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef int64_t lld;
typedef pair<int, int> pii;
typedef long double ld;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
  return out << "(" << p.ff << ", " << p.ss << ")";
}

template<typename Iter>
ostream& outIt(ostream& out, Iter b, Iter e){
  for(Iter i = b; i != e; i++)
    out << (i==b?"":" ") << *i;
  return out;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> v){
  return outIt(out << '[', all(v)) << ']';
}


template<typename T1, typename T2>
ostream& operator<<(ostream& out, map<T1, T2> m){
  return outIt(out << '{', all(m)) << '}';
}

/*
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
*/

template<typename T1, typename T2>
pair<T1, T2>& operator+=(pair<T1, T2>& a, pair<T1, T2> p){
  return a.ff += p.ff, a.ss += p.ss, a;
}

set<pii> cols;
vector<int> nexts, cn, adv;
order_statistics_tree<int> cols_ord;
void ComputeAdvice(int *C, int N, int K, int M) {
  cn.resize(N, INT_MAX); nexts.resize(N); //adv.resize(N);
  for(int i = N-1; i >= 0; i--){
    nexts[i] = cn[C[i]];
    cn[C[i]] = i;
  }
  //cout << nexts << cn << endl;
  for(int i = 0; i < K; i++)cols.insert({cn[i], i}), cols_ord.insert(i);
  for(int i = 0; i < N; i++){
    //cout << i << endl;
    if(cols_ord.find(C[i]) == cols_ord.end()){
      auto take_out = *prev(cols.end());
      //cout << "oops" << take_out << endl;
      adv.pb((int)cols_ord.order_of_key(take_out.ss));
      cols_ord.erase(take_out.ss);
      cols.erase(take_out);
      cols_ord.insert(C[i]);
    }else{
      cols.erase({cn[C[i]], C[i]});
    }
    cn[C[i]] = nexts[i];
    cols.insert({cn[C[i]], C[i]});
  }
  int bitlen = __lg(K-1)+1;
  //cout << adv << endl;
  for(auto i: adv){
    for(int j = 1; j < K; j <<=1)
      WriteAdvice(i&j);
  }
}
#include "assistant.h"

#include<bits/stdc++.h>
using namespace std;

#include<bits/extc++.h>
using namespace __gnu_pbds;
template<typename T>
using order_statistics_tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//#define int lld
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef int64_t lld;
typedef pair<int, int> pii;
typedef long double ld;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
  return out << "(" << p.ff << ", " << p.ss << ")";
}

template<typename Iter>
ostream& outIt(ostream& out, Iter b, Iter e){
  for(Iter i = b; i != e; i++)
    out << (i==b?"":" ") << *i;
  return out;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> v){
  return outIt(out << '[', all(v)) << ']';
}


template<typename T1, typename T2>
ostream& operator<<(ostream& out, map<T1, T2> m){
  return outIt(out << '{', all(m)) << '}';
}

//template<typename T>
//using min_heap = priority_queue<T, vector<T>, greater<T>>;

template<typename T1, typename T2>
pair<T1, T2>& operator+=(pair<T1, T2>& a, pair<T1, T2> p){
  return a.ff += p.ff, a.ss += p.ss, a;
}



/*
void ComputeAdvice(int *C, int N, int K, int M) {
  cn.resize(N, INT_MAX); nexts.resize(N); //adv.resize(N);
  for(int i = N-1; i >= 0; i--){
    nexts[i] = cn[C[i]];
    cn[C[i]] = i;
  }
  //cout << nexts << cn << endl;
  for(int i = 0; i < K; i++)cols.insert({cn[i], i}), cols_ord.insert(i);
  for(int i = 0; i < N; i++){
    //cout << i << endl;
    if(cols_ord.find(C[i]) == cols_ord.end()){
      auto take_out = *prev(cols.end());
      //cout << "oops" << take_out << endl;
      adv.pb((int)cols_ord.order_of_key(take_out.ss));
      cols_ord.erase(take_out.ss);
      cols.erase(take_out);
      cols_ord.insert(C[i]);
    }else{
      cols.erase({cn[C[i]], C[i]});
    }
    cn[C[i]] = nexts[i];
    cols.insert({cn[C[i]], C[i]});
  }
  int bitlen = __lg(K-1)+1;
  for(auto i: adv){
    for(int j = 1; j < K; j <<=1)
      WriteAdvice(i&j);
  }
}
*/

vector<int> tadv;
order_statistics_tree<int> tcols_ord;

void Assist(unsigned char *A, int N, int K, int R) {
  int bitlen = __lg(K)+1;
  tadv.resize(N);
  for(int i = 0, k = 0; i < R; k++)
    for(int j = 1; j < K; j<<=1, i++)
      tadv[k] += j*A[i];
  //cout << tadv << endl;
  for(int i = 0; i < K; i++)tcols_ord.insert(i);
  for (int i = 0, j = 0, x; i < N; i++) {
    int req = GetRequest();
    if(tcols_ord.find(req) == tcols_ord.end())
      x = *tcols_ord.find_by_order(tadv[j++]), PutBack(x), tcols_ord.erase(x), tcols_ord.insert(req);
  }
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:80:7: warning: unused variable 'bitlen' [-Wunused-variable]
   80 |   int bitlen = __lg(K-1)+1;
      |       ^~~~~~

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:90:7: warning: unused variable 'bitlen' [-Wunused-variable]
   90 |   int bitlen = __lg(K)+1;
      |       ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 916 KB Output is correct
2 Incorrect 1 ms 900 KB Error - advice must be 0 or 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1280 KB Error - advice must be 0 or 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 6896 KB Error - advice must be 0 or 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1124 KB Error - advice must be 0 or 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 125 ms 7448 KB Error - advice must be 0 or 1
2 Incorrect 140 ms 8176 KB Error - advice must be 0 or 1
3 Incorrect 130 ms 8432 KB Error - advice must be 0 or 1
4 Incorrect 126 ms 8432 KB Error - advice must be 0 or 1
5 Incorrect 129 ms 8432 KB Error - advice must be 0 or 1
6 Incorrect 133 ms 8688 KB Error - advice must be 0 or 1
7 Incorrect 147 ms 8432 KB Error - advice must be 0 or 1
8 Incorrect 145 ms 8432 KB Error - advice must be 0 or 1
9 Incorrect 140 ms 8432 KB Error - advice must be 0 or 1
10 Incorrect 138 ms 8944 KB Error - advice must be 0 or 1