답안 #623177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623177 2022-08-05T09:34:59 Z ollel 최후의 만찬 (IOI12_supper) C++14
0 / 100
212 ms 8696 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()) {
      assert(pq.size() != 0);
      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;
      |                                                          ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 1236 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 152 ms 6888 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 936 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 139 ms 7776 KB Execution killed with signal 6
2 Runtime error 150 ms 8108 KB Execution killed with signal 6
3 Runtime error 185 ms 8520 KB Execution killed with signal 6
4 Runtime error 186 ms 8652 KB Execution killed with signal 6
5 Runtime error 211 ms 8620 KB Execution killed with signal 6
6 Runtime error 193 ms 8604 KB Execution killed with signal 6
7 Runtime error 212 ms 8696 KB Execution killed with signal 6
8 Runtime error 187 ms 8648 KB Execution killed with signal 6
9 Runtime error 192 ms 8624 KB Execution killed with signal 6
10 Runtime error 80 ms 8272 KB Execution killed with signal 6