Submission #623168

# Submission time Handle Problem Language Result Execution time Memory
623168 2022-08-05T09:29:44 Z ollel Last supper (IOI12_supper) C++14
0 / 100
2500 ms 4560 KB
using namespace std;
#include <bits/stdc++.h>
#include "advisor.h"


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<bool> vb;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
//
// void WriteAdvice(int x) {
//   cout << x << " ";
// }

void ComputeAdvice(int *c, int n, int k, int m) {
  bool debug = false;
  int ans = 0;
  set<int> scaffold;
  rep(i,0,k) scaffold.insert(i);


  vi advice(2*n, 0);
  vi added(n, 0);
  rep(i,0,k) added[i] = i;

  vi nextOccurenceOfColor(n,1e9);
  vi sweep(n,1e9);
  for (int i = n - 1; i >= 0; i--) {
    nextOccurenceOfColor[i] = sweep[c[i]];
    sweep[c[i]] = i;
  }

  priority_queue<pair<int,int>> pq;
  rep(i,0,k) pq.push({sweep[i], i});

  if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
  rep(i,0,n) {
    int color = c[i];
    added[color] = n+i;
    pq.push({nextOccurenceOfColor[i], c[i]});


    if (scaffold.find(color) != scaffold.end()) {
      if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;

      continue;
    }


    int toRemove = -1;
    while (scaffold.find(toRemove) == scaffold.end()) {
      pair<int,int> res = pq.top(); pq.pop();
      if (debug) cout << "popped " << res.first << ", "<< res.second << endl;
      toRemove = res.second;
    }

    advice[added[toRemove]] = 1;
    if (debug) cout << "advice at " << added[toRemove] << endl;
    scaffold.erase(toRemove);
    ans++;

    scaffold.insert(c[i]);
    if (debug) cout << "pushing " << c[i] << " with next occ " << nextOccurenceOfColor[i] << endl;
    if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;

  }
  rep(i,0,2*n) WriteAdvice(advice[i]);
  if (debug) cout << "\nanswer: " << ans << endl;
}

// int main() {
//   int c[] ={4, 1, 2, 1, 2, 1, 4, 2};
//   ComputeAdvice(c, 8, 2, -1);
// }
using namespace std;
#include <bits/stdc++.h>
#include "assistant.h"


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<bool> vb;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back



void Assist(unsigned char *a, int n, int k, int r) {
  set<int> scaffold;
  rep(i,0,k) scaffold.insert(i);

  vector<int> advice(2*n);
  rep(i,0,2*n) advice[i] = a[i];
  queue<int> q;
  rep(i,0,k) if (advice[i] == 1) q.push(i);

  rep(i,0,n) {
    int nextColor = GetRequest();
    if (scaffold.find(nextColor) == scaffold.end()) {
      int rem = q.front(); q.pop();
      PutBack(rem);
      scaffold.erase(rem);
      scaffold.insert(nextColor);
    }
    if (advice[n + i] == 1) {
      q.push(nextColor);
    }
  }
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:40:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   40 |   if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
      |   ^~
advisor.cpp:40:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   40 |   if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
      |                                                        ^~~~
advisor.cpp:48:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   48 |       if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
      |       ^~
advisor.cpp:48:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   48 |       if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
      |                                                            ^~~~
advisor.cpp:68:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   68 |     if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
      |     ^~
advisor.cpp:68:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   68 |     if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
      |                                                          ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2582 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2566 ms 596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2574 ms 3620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 936 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2584 ms 3992 KB Time limit exceeded
2 Execution timed out 2594 ms 4052 KB Time limit exceeded
3 Execution timed out 2591 ms 4432 KB Time limit exceeded
4 Execution timed out 2585 ms 4424 KB Time limit exceeded
5 Execution timed out 2584 ms 4424 KB Time limit exceeded
6 Execution timed out 2587 ms 4424 KB Time limit exceeded
7 Execution timed out 2584 ms 4496 KB Time limit exceeded
8 Execution timed out 2565 ms 4560 KB Time limit exceeded
9 Execution timed out 2599 ms 4440 KB Time limit exceeded
10 Execution timed out 2582 ms 4308 KB Time limit exceeded