답안 #304036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304036 2020-09-21T01:22:16 Z Fdg 버섯 세기 (IOI20_mushrooms) C++14
0 / 100
162 ms 560 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include "mushrooms.h"

using namespace std;

const int VAL = 141;

vector<int> a, b;

int count_mushrooms(int n) {
  a.clear(); b.clear();

  srand(time(NULL));
  vector<int> v;
  for (int i = 1; i < n; ++i)
    v.push_back(i);
  random_shuffle(v.begin(), v.end());

  int ans = 0, pos = 0;

  a.push_back(0);
  while (a.size() < VAL || b.size() < VAL) {
    if (a.size() > 1) {
      vector<int> arr = {a[0]};
      if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;
      arr.push_back(a[1]); 
      if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;

      int ret = use_machine(arr);
      if (ret & 2) {
        b.push_back(arr[1]);
      } else {
        a.push_back(arr[1]);
      }
      if (arr.size() > 3) {
        if (ret & 1) {
          b.push_back(arr[3]);
        } else {
          a.push_back(arr[3]);
        }
      }
    } else if (b.size() > 1) {
      vector<int> arr = {b[0]};
      if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;
      arr.push_back(b[1]); 
      if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;

      int ret = use_machine(arr);
      if (ret & 2) {
        a.push_back(arr[1]);
      } else {
        b.push_back(arr[1]);
      }
      if (arr.size() > 3) {
        if (ret & 1) {
          a.push_back(arr[3]);
        } else {
          b.push_back(arr[3]);
        }
      }
    } else {
      vector<int> arr = {a[0]};
      if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;

      int ret = use_machine(arr);
      if (ret & 1) {
        b.push_back(arr[1]);
      } else {
        a.push_back(arr[1]);
      }
    }
  }

  ans = a.size();

  if (a.size() >= b.size()) {
    while (pos < (int) v.size()) {
      vector<int> arr;
      int used = 0;
      for (int i = 0; i < a.size(); ++i) {
        arr.push_back(a[i]);
        if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos, ++used;
        else break;
      }
      int ret = use_machine(arr);
      int diff = (ret / 2) + (ret & 1);
      ans += used - diff;
    }
  } else {
    while (pos < (int) v.size()) {
      vector<int> arr;
      int used = 0;
      for (int i = 0; i < b.size(); ++i) {
        arr.push_back(b[i]);
        if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos, ++used;
        else break;
      }
      int ret = use_machine(arr);
      int diff = (ret / 2) + (ret & 1);
      ans += diff;
    }
  }

  return ans;
}

// int count_mushrooms(int n) {
//   int ans = 1;
//   for (int i = 1; i < n; i += 2) {
//     vector<int> v;
//     if (i + 1 < n) v = {i, 0, i + 1};
//     else v = {i, 0};
//     int ret = use_machine(v);
//     ans += (v.size() - 1) - ret;
//   }
//   return ans;
// }

// int main() {
//   ios::sync_with_stdio(false);

//   return 0; 
// }

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:84:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |       for (int i = 0; i < a.size(); ++i) {
      |                       ~~^~~~~~~~~~
mushrooms.cpp:97:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |       for (int i = 0; i < b.size(); ++i) {
      |                       ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 560 KB Too many queries.
2 Halted 0 ms 0 KB -