답안 #829619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829619 2023-08-18T13:24:59 Z MilosMilutinovic 최후의 만찬 (IOI12_supper) C++14
100 / 100
135 ms 19104 KB
#include "advisor.h"
#include <bits/stdc++.h>

using namespace std;

void ComputeAdvice(int *c, int n, int k, int m) {
  vector<int> has(n);
  for (int i = 0; i < k; i++) {
    has[i] = true;
  }
  vector<set<int>> pos(n);
  for (int i = 0; i < n; i++) {
    pos[c[i]].insert(i);
  }
  set<pair<int, int>> st;
  for (int i = 0; i < k; i++) {
    if (pos[i].empty()) {
      st.emplace(n, i);
    } else {
      st.emplace(*pos[i].begin(), i);
    }
  }
  vector<bool> use(n);
  for (int i = 0; i < n; i++) {
    pos[c[i]].erase(pos[c[i]].find(i));
    if (has[c[i]]) {
      st.erase(st.find(make_pair(i, c[i])));
      if (pos[c[i]].empty()) {
        st.emplace(n, c[i]);
      } else {
        st.emplace(*pos[c[i]].begin(), c[i]);
      }
      use[i] = true;
      continue;
    }
    auto it = prev(st.end());
    int x = it->second;
    st.erase(it);
    has[x] = false;
    has[c[i]] = true;
    if (pos[c[i]].empty()) {
      st.emplace(n, c[i]);
    } else {
      st.emplace(*pos[c[i]].begin(), c[i]);
    }
  }
  vector<vector<int>> p(n);
  for (int i = 0; i < n; i++) {
    p[c[i]].push_back(i);
  }
  for (int i = 0; i < k; i++) {
    if (p[i].empty() || !use[p[i][0]]) {
      WriteAdvice(0);
    } else {
      WriteAdvice(1);
    }
  }
  vector<int> ptr(n);
  for (int i = 0; i < n; i++) {
    if (ptr[c[i]] == (int) p[c[i]].size() - 1) {
      WriteAdvice(0);
    } else {
      WriteAdvice(use[p[c[i]][ptr[c[i]] + 1]] ? 1 : 0);
    }
    ptr[c[i]] += 1;
  }
}
#include "assistant.h"
#include <bits/stdc++.h>

using namespace std;

void Assist(unsigned char *a, int n, int k, int r) {
  set<int> st;
  for (int i = 0; i < k; i++) {
    if (a[i] == 0) {
      st.insert(i);
    }
  }
  vector<bool> has(n);
  for (int i = 0; i < k; i++) {
    has[i] = true;
  }
  for (int i = 0; i < n; i++) {
    int req = GetRequest();
    if (!has[req]) {
      has[req] = true;
      PutBack(*st.begin());
      has[*st.begin()] = false;
      st.erase(st.begin());
    }
    if (a[k + i] == 0) {
      st.insert(req);
    }
  }
}

/*
4 2 65000
2 0 3 0

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 508 KB Output is correct
2 Correct 1 ms 520 KB Output is correct
3 Correct 2 ms 908 KB Output is correct
4 Correct 3 ms 944 KB Output is correct
5 Correct 3 ms 1184 KB Output is correct
6 Correct 4 ms 1220 KB Output is correct
7 Correct 4 ms 1476 KB Output is correct
8 Correct 4 ms 1472 KB Output is correct
9 Correct 4 ms 1444 KB Output is correct
10 Correct 6 ms 1452 KB Output is correct
11 Correct 4 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2140 KB Output is correct
2 Correct 45 ms 7332 KB Output is correct
3 Correct 94 ms 19104 KB Output is correct
4 Correct 64 ms 13696 KB Output is correct
5 Correct 80 ms 13780 KB Output is correct
6 Correct 78 ms 14328 KB Output is correct
7 Correct 102 ms 17572 KB Output is correct
8 Correct 73 ms 15724 KB Output is correct
9 Correct 68 ms 13088 KB Output is correct
10 Correct 107 ms 18604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 13696 KB Output is correct
2 Correct 109 ms 17968 KB Output is correct
3 Correct 102 ms 18096 KB Output is correct
4 Correct 113 ms 18112 KB Output is correct
5 Correct 105 ms 17496 KB Output is correct
6 Correct 105 ms 18112 KB Output is correct
7 Correct 99 ms 18104 KB Output is correct
8 Correct 84 ms 18120 KB Output is correct
9 Correct 83 ms 15684 KB Output is correct
10 Correct 97 ms 18160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1296 KB Output is correct
2 Correct 6 ms 1472 KB Output is correct
3 Correct 3 ms 1188 KB Output is correct
4 Correct 4 ms 1224 KB Output is correct
5 Correct 5 ms 1224 KB Output is correct
6 Correct 4 ms 1228 KB Output is correct
7 Correct 5 ms 1480 KB Output is correct
8 Correct 4 ms 1468 KB Output is correct
9 Correct 5 ms 1472 KB Output is correct
10 Correct 6 ms 1736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 16448 KB Output is correct - 120000 bits used
2 Correct 114 ms 16584 KB Output is correct - 122000 bits used
3 Correct 99 ms 16984 KB Output is correct - 125000 bits used
4 Correct 135 ms 16864 KB Output is correct - 125000 bits used
5 Correct 107 ms 16880 KB Output is correct - 125000 bits used
6 Correct 118 ms 16864 KB Output is correct - 125000 bits used
7 Correct 111 ms 17028 KB Output is correct - 124828 bits used
8 Correct 130 ms 16868 KB Output is correct - 124910 bits used
9 Correct 120 ms 17016 KB Output is correct - 125000 bits used
10 Correct 102 ms 16960 KB Output is correct - 125000 bits used