Submission #602095

#TimeUsernameProblemLanguageResultExecution timeMemory
602095definitelynotmeeCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
0 ms208 KiB
#include "mushrooms.h" #include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define all(x) x.begin(), x.end() using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using matrix = vector<vector<T>>; const int initial = 200*sqrt(2)-1; int count_mushrooms(int n) { if(n <= 3){ int resp = 1; for(int i = 1; i < n; i++) resp+=use_machine({0,i})^1; return resp; } vector<int> start(initial,-1); start[1] = use_machine({0,1}); start[2] = use_machine({0,2}); int q1 = 0, q2 = 1, qresp = 1; if(start[1] != 0){ if(start[2] != 0){ q1 = 1, q2 = 2, qresp = 0; } else q2 = 2; } for(int i = 3; i+1 < min(initial,n); i+=2){ int ret = use_machine({q1,i+1,q2,i}); for(int j = 0; j < 2; j++){ if((1<<j)&ret) start[i+j] = qresp^1; else start[i+j] = qresp; } } if(start[min(initial,n)-1] == -1){ start[min(initial,n)-1] = use_machine({0,min(initial,n)-1})^1; } int resp = 0; array<vector<int>,2> mush; for(int i = 0; i < min(initial,n); i++){ resp+=start[i]; mush[start[i]].push_back(i); } int id = initial; while(id < n){ int type = mush[0].size() > mush[1].size() ? 0 : 1; vector<int> query; int ptr = 0, ct = 0; while(id < n && ptr < mush[type].size()){ query.push_back(mush[type][ptr]); query.push_back(id); ptr++; id++; ct++; } int ret = use_machine(query); resp+=type ? (ret+1)/2 : ct-(ret+1)/2; if(ret&1) mush[type^1].push_back(id-1); } return resp; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:54:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         while(id < n && ptr < mush[type].size()){
      |                         ~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...