Submission #126860

# Submission time Handle Problem Language Result Execution time Memory
126860 2019-07-08T14:24:20 Z RockyB Last supper (IOI12_supper) C++17
100 / 100
395 ms 40752 KB
#include "advisor.h"
#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back

#define sz(x) (int)x.size()

#define rep(z, a, b) for (int z = (a); (z) <= (b); z++)
#define per(z, a, b) for (int z = (a); (z) >= (b); z--)

using namespace std;

const int MAXN = (int)2e5 + 7;


vector <int> nxt[MAXN];
int del_val[MAXN];
bool good[MAXN];
void ComputeAdvice(int *C, int N, int K, int M) {
  per(i, N - 1, 0) nxt[i].pb(N);
  per(i, N - 1, 0) nxt[C[i]].pb(i);

  set < pair <int, int > > st;
  rep(i, 0, K - 1) st.insert({nxt[i].back(), i});
  memset(del_val, -1, sizeof(del_val));
  rep(i, 0, N - 1) {
    while (sz(st) && st.begin() -> f <= i) {
      int x = st.begin() -> s;
      st.erase(st.begin());
      nxt[x].pp();
      st.insert({nxt[x].back(), x});
    }
    if (st.count({nxt[C[i]].back(), C[i]})) {
      continue;
    }
    int x = st.rbegin() -> s;
    st.erase(--st.end());
    st.insert({nxt[C[i]].back(), C[i]});
    del_val[i] = x;
  } 
  map <int, int> ask, del;
  per(i, N - 1, 0) {
    /// good if ask < del
    if (ask.count(C[i]) && (!del.count(C[i]) || ask[C[i]] < del[C[i]])) {
      good[i] = 1;
    }
    ask[C[i]] = i;
    del[del_val[i]] = i;
  }
  rep(i, 0, K - 1) {
    if (ask.count(i) && (!del.count(i) || ask[i] < del[i])) {
      WriteAdvice(1);
    }
    else WriteAdvice(0);
  }
  rep(i, 0, N - 1) {
    WriteAdvice(good[i]);
  }
}
#include "assistant.h"
#include <bits/stdc++.h>
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
 
#define sz(x) (int)x.size()
 
#define rep(z, a, b) for (int z = (a); (z) <= (b); z++)
#define per(z, a, b) for (int z = (a); (z) >= (b); z--)
 
using namespace std;
 
const int MAXN = (int)2e5 + 7;
 
void Assist(unsigned char *A, int N, int K, int R) {
  /* for (int i = 0; i < R; i++) {
    cerr << (int)A[i] << ' ';
  }
  exit(0); */
  set <int> a[2];
  rep(i, 0, K - 1) a[A[i]].insert(i);
  rep(i, K, K + N - 1) {
    int val = GetRequest();
    
    /* rep(j, 0, 1) {
      cerr << j << " -> ";
      for (auto it : a[j]) cerr << it << ' ';
      cerr << endl;
    } */
    
    if (a[0].count(val) || a[1].count(val)) {
      rep(j, 0, 1) a[j].erase(val);
      a[A[i]].insert(val);  
      continue;
    }
    //cerr << " -> " << *a[0].begin() << endl;
    PutBack(*a[0].begin());
    a[0].erase(a[0].begin());
    
    rep(j, 0, 1) a[j].erase(val);
    a[A[i]].insert(val);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11504 KB Output is correct
2 Correct 9 ms 11504 KB Output is correct
3 Correct 11 ms 11760 KB Output is correct
4 Correct 12 ms 12016 KB Output is correct
5 Correct 18 ms 12528 KB Output is correct
6 Correct 19 ms 12784 KB Output is correct
7 Correct 17 ms 12272 KB Output is correct
8 Correct 17 ms 13040 KB Output is correct
9 Correct 18 ms 12784 KB Output is correct
10 Correct 20 ms 12728 KB Output is correct
11 Correct 19 ms 12784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 14072 KB Output is correct
2 Correct 130 ms 20632 KB Output is correct
3 Correct 355 ms 38296 KB Output is correct
4 Correct 223 ms 33872 KB Output is correct
5 Correct 247 ms 34032 KB Output is correct
6 Correct 295 ms 34544 KB Output is correct
7 Correct 324 ms 34656 KB Output is correct
8 Correct 258 ms 36080 KB Output is correct
9 Correct 177 ms 24056 KB Output is correct
10 Correct 353 ms 35056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 30088 KB Output is correct
2 Correct 334 ms 34712 KB Output is correct
3 Correct 326 ms 34800 KB Output is correct
4 Correct 322 ms 33872 KB Output is correct
5 Correct 301 ms 30704 KB Output is correct
6 Correct 332 ms 35072 KB Output is correct
7 Correct 333 ms 34344 KB Output is correct
8 Correct 311 ms 40752 KB Output is correct
9 Correct 264 ms 30448 KB Output is correct
10 Correct 328 ms 35056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12528 KB Output is correct
2 Correct 19 ms 13040 KB Output is correct
3 Correct 15 ms 12272 KB Output is correct
4 Correct 16 ms 12784 KB Output is correct
5 Correct 17 ms 12784 KB Output is correct
6 Correct 17 ms 12784 KB Output is correct
7 Correct 18 ms 12784 KB Output is correct
8 Correct 18 ms 12784 KB Output is correct
9 Correct 18 ms 12784 KB Output is correct
10 Correct 21 ms 12784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 34288 KB Output is correct - 120000 bits used
2 Correct 333 ms 34544 KB Output is correct - 122000 bits used
3 Correct 334 ms 34496 KB Output is correct - 125000 bits used
4 Correct 335 ms 34544 KB Output is correct - 125000 bits used
5 Correct 334 ms 34544 KB Output is correct - 125000 bits used
6 Correct 350 ms 34544 KB Output is correct - 125000 bits used
7 Correct 338 ms 34488 KB Output is correct - 124828 bits used
8 Correct 332 ms 34544 KB Output is correct - 124910 bits used
9 Correct 325 ms 34544 KB Output is correct - 125000 bits used
10 Correct 395 ms 39664 KB Output is correct - 125000 bits used