Submission #760025

#TimeUsernameProblemLanguageResultExecution timeMemory
760025aryan12Counting Mushrooms (IOI20_mushrooms)C++17
80.71 / 100
8 ms464 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; int count_mushrooms(int n) { vector<int> a_type, b_type; a_type.push_back(0); int current_mushroom = 1; int answer = 0; while(current_mushroom < n) { if(a_type.size() > b_type.size()) { // use a_type.size() int cnt = min((int)a_type.size(), n - 1 - current_mushroom + 1); vector<int> query; for(int i = 0; i < cnt; i++) { query.push_back(a_type[i]); query.push_back(current_mushroom + i); } int response = use_machine(query); int last_one = current_mushroom + cnt - 1; if(response & 1) // last one is b_type { b_type.push_back(last_one); response -= 1; } else { a_type.push_back(last_one); } int total = query.size() - 2; answer += (total - response) / 2; current_mushroom += cnt; } else { int cnt = min((int)b_type.size(), n - 1 - current_mushroom + 1); vector<int> query; for(int i = 0; i < cnt; i++) { query.push_back(b_type[i]); query.push_back(current_mushroom + i); } int response = use_machine(query); int last_one = current_mushroom + cnt - 1; if(response & 1) { a_type.push_back(last_one); response -= 1; } else { b_type.push_back(last_one); } answer += response / 2; current_mushroom += cnt; } } return answer + (int)a_type.size(); }
#Verdict Execution timeMemoryGrader output
Fetching results...