Submission #1079783

#TimeUsernameProblemLanguageResultExecution timeMemory
1079783HD1Counting Mushrooms (IOI20_mushrooms)C++14
56.93 / 100
8 ms600 KiB
#include "mushrooms.h" #include <vector> #include <iostream> using namespace std; int count_mushrooms(int n) { if(n < 100){ int res = 1; for(int i = 2; i <= n;i++){ int ans = use_machine({0,i-1}); res += 1 - ans; } return res; } int k = -1,mini = 1e9; for(int i = 1; i < n; i++){ int v = 2*i + ( n - (2*i + 1 ) +i)/(i+1); if(mini > v) mini = v, k = i; } vector<int> A,B; A.push_back(1); for(int i = 2; i <= 2*k + 1;i++){ int ans = use_machine({0,i-1}); if(ans == 0) A.push_back(i); else B.push_back(i); } // cout << k << endl; bool isA = true; int res = A.size(); if(B.size() > A.size()) swap(A,B), isA = false; for(int i = 1; i <= ( n - (2*k + 1 ) +k)/(k+1); i++){ int ini = 2*k+2 + (i-1)*(k+1) ; int fin = min(n+1, 2*k+2 + (i)*(k+1)); vector<int> q; // cout << ini << " " << fin << endl; for(int j = ini; j < fin; j++){ q.push_back(j-1); q.push_back(A[j-ini]-1); } int ans = use_machine(q); if(ans&1) ans = 1 + ans/2; else ans = ans/2; res += ( isA ? fin-ini-ans : ans); //cout << "RES: "<< res << " " << ans << endl; } // A A B A B A -> 5 -> 2 // B A A A A A -> 1 -> 1 + 1/1 // p A p A p A -> x -> x/2 - // -> 1 + x/2 // cout << res << endl; // 1 query tenemos que un valr i -> i+1 tipos -> 2*i -> i+1 del mismo tipo // n/(i+2) return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...