Advertisement
erek1e

IOI '20 - Mushrooms (87.5969pts)

Mar 5th, 2023
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include "mushrooms.h"
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int count_mushrooms(int n) {
  7.     int s = 141; // sqrt(20000)
  8.     // ADD RANDOM_SHUFFLE LATER
  9.    
  10.     // find first 2s values pairwise
  11.     vector<int> id[2]; // A, B
  12.     id[0].push_back(0);
  13.     vector<int> m;
  14.     int last = min(2*s, n);
  15.     for (int i = 1; i < last; ) {
  16.         if (i+1 < last && (id[0].size() >= 2 || id[1].size() >= 2)) {
  17.             int same = 0;
  18.             if (id[0].size() < 2) same = 1;
  19.  
  20.             m = {id[same][0], i, id[same][1], i+1};
  21.             int x = use_machine(m);
  22.             if (x & 1) id[1-same].push_back(i+1);
  23.             else id[same].push_back(i+1);
  24.             if (x & 2) id[1-same].push_back(i);
  25.             else id[same].push_back(i);
  26.             i += 2;
  27.         } else {
  28.             m = {0, i};
  29.             if (use_machine(m)) id[1].push_back(i);
  30.             else id[0].push_back(i);
  31.             i++;
  32.         }
  33.     }
  34.  
  35.     // find the rest of the values as blocks of s
  36.     int A = id[0].size();
  37.     for (int i = last; i < n; ) {
  38.         int big = (id[1].size() > id[0].size() ? 1 : 0);
  39.         int cnt = min((int)id[big].size(), n-i);
  40.         m.clear();
  41.         for (int j = 0; j < cnt; ++j) {
  42.             m.push_back(i+j);
  43.             m.push_back(id[big][j]);
  44.         }
  45.         int x = use_machine(m);
  46.         if (x & 1) {
  47.             id[1-big].push_back(i);
  48.             ++x;
  49.         } else id[big].push_back(i);
  50.         x /= 2;
  51.         if (big == 0) x = cnt-x;
  52.         A += x;
  53.         i += cnt;
  54.     }
  55.     return A;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement