답안 #1002993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002993 2024-06-19T23:40:52 Z MilosMilutinovic 버섯 세기 (IOI20_mushrooms) C++14
0 / 100
1 ms 344 KB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

int count_mushrooms(int n) {
  if (n <= 227) {
    int res = 1;
    for (int i = 1; i < n; i++) {
      res += 1 - use_machine({0, i});
    }
    return res;
  }
  const int C = 130;
  vector<int> a(1, 0);
  vector<int> b;
  for (int i = 1; i <= 2; i++) {
    if (use_machine({0, i})) {
      b.push_back(i); 
    } else {
      a.push_back(i);
    }
  }
  int res = (int) a.size();
  int ptr = 3;
  while ((int) a.size() < C && (int) b.size() < C) {
    if (ptr >= n) {
      break;
    }
    if (ptr + 2 >= n) {
      for (int i = ptr; i < n; i++) {
        if (use_machine({0, i}) == 0) {
          res += 1;
        }
      }
      ptr = n;
      break;
    }
    int x = ptr, y = ptr + 1, z = ptr + 2;
    if (a.size() > b.size()) {
      int p = use_machine({x, a[0], y, a[1], z});
      if (p == 0) {
        res += 3;
        a.push_back(x);
        a.push_back(y);
        a.push_back(z);
      } else if (p == 4) {
        b.push_back(x);
        b.push_back(y);
        b.push_back(z);
      } else if (p == 2) {
        int q = use_machine({a[0], y});
        if (q == 0) {
          a.push_back(y);
          res += 1;
          b.push_back(x);
          b.push_back(z);
        } else {
          a.push_back(x);
          a.push_back(z);
          res += 2;
          b.push_back(y);
        }
      } else if (p == 1) {
        int q = use_machine({a[0], x});
        if (q == 0) {
          a.push_back(x);
          a.push_back(y);
          res += 2;
          b.push_back(z); 
        } else {
          a.push_back(y);
          a.push_back(z);
          res += 2;
          b.push_back(x);
        }
      } else {
        int q = use_machine({a[0], x});
        if (q == 0) {
          a.push_back(x);
          res += 1;
          b.push_back(y);
          b.push_back(z);
        } else {
          a.push_back(z);
          res += 1;
          b.push_back(x);
          b.push_back(y);
        }
      }
    } else {
      int p = 4 - use_machine({x, a[0], y, a[1], z});
      if (p == 0) {
        res += 3;
        a.push_back(x);
        a.push_back(y);
        a.push_back(z);
      } else if (p == 4) {
        b.push_back(x);
        b.push_back(y);
        b.push_back(z);
      } else if (p == 2) {
        int q = 1 - use_machine({a[0], y});
        if (q == 0) {
          a.push_back(y);
          res += 1;
          b.push_back(x);
          b.push_back(z);
        } else {
          a.push_back(x);
          a.push_back(z);
          res += 2;
          b.push_back(y);
        }
      } else if (p == 1) {
        int q = 1 - use_machine({a[0], x});
        if (q == 0) {
          a.push_back(x);
          a.push_back(y);
          res += 2;
          b.push_back(z); 
        } else {
          a.push_back(y);
          a.push_back(z);
          res += 2;
          b.push_back(x);
        }
      } else {
        int q = 1 - use_machine({b[0], x});
        if (q == 0) {
          a.push_back(x);
          res += 1;
          b.push_back(y);
          b.push_back(z);
        } else {
          a.push_back(z);
          res += 1;
          b.push_back(x);
          b.push_back(y);
        }
      }
    }
    ptr += 3;
  }
  if (ptr >= n) {
    return res;
  }
  while (ptr < n) {
    if (a.size() > b.size()) {
      int c = min(n - ptr, (int) a.size());
      vector<int> qv;
      for (int i = 0; i < c; i++) {
        qv.push_back(a[i]);
        qv.push_back(ptr + i);
      }
      int d = use_machine(qv);
      if (d % 2 == 0) {
        a.push_back(qv.back());
        res += 1;
      } else {
        b.push_back(qv.back());
      }
      res += (c - 1 - (d / 2));
      ptr += c;
    } else {
      int c = min(n - ptr, (int) b.size());
      vector<int> qv;
      for (int i = 0; i < c; i++) {
        qv.push_back(b[i]);
        qv.push_back(ptr + i);
      }
      int d = use_machine(qv);
      if (d % 2 == 0) {
        b.push_back(qv.back());
      } else {
        a.push_back(qv.back());
        res += 1;
      }
      res += d / 2;
      ptr += c;
    }
  }
  return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Duplicate value 0 in the query array.
7 Halted 0 ms 0 KB -