Submission #940930

#TimeUsernameProblemLanguageResultExecution timeMemory
940930TranGiaHuy1508Toxic Gene (NOI23_toxic)C++17
67.60 / 100
25 ms600 KiB
#include <bits/stdc++.h> using namespace std; #include "toxic.h" enum BacteriaType { REGULAR = 'R', STRONG = 'S', TOXIC = 'T' }; int query(vector<pair<int, int>> samples){ vector<int> species; for (auto [type, cnt]: samples){ for (int _ = 0; _ < cnt; _++) species.push_back(type + 1); } return query_sample(species); } void determine_type(int n){ vector<char> vec(n, REGULAR); vector<int> other; static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<int> lst(n); iota(lst.begin(), lst.end(), 0); vector<int> bruh; int tox = 0; while (!lst.empty()){ shuffle(lst.begin(), lst.end(), rng); vector<pair<int, int>> crrq; int a = 1; while (!lst.empty() && a < 256){ crrq.emplace_back(lst.back(), a); a <<= 1; lst.pop_back(); } int mask = query(crrq); vector<int> dead; if (mask == (1 << crrq.size()) - 1){ for (auto elem: crrq) bruh.push_back(elem.first); continue; } else{ for (int j = 0; j < (int)crrq.size(); j++){ if ((mask >> j) & 1) vec[crrq[j].first] = STRONG; else dead.push_back(crrq[j].first); } } int l = 0, r = dead.size() - 1; while (l < r){ int mid = (l + r) >> 1; vector<pair<int, int>> subq; for (int j = 0; j <= mid; j++) subq.emplace_back(dead[j], 1); int any = query(subq); if (any) l = mid + 1; else r = mid; } vec[dead[l]] = TOXIC; tox = dead[l]; for (int j = l+1; j < (int)dead.size(); j++) lst.push_back(dead[j]); } for (int i = 0; i < n; i++){ bool valid = true; for (auto elem: bruh) if (elem == i) valid = false; if (valid) answer_type(i+1, vec[i]); } while (!bruh.empty()){ vector<pair<int, int>> crrq; int a = 1; while (!bruh.empty() && a < 256){ crrq.emplace_back(bruh.back(), a); a <<= 1; bruh.pop_back(); } crrq.emplace_back(tox, 1); int mask = query(crrq); for (int j = 0; j < (int)crrq.size() - 1; j++){ if ((mask >> j) & 1) vec[crrq[j].first] = STRONG; } } for (int i = 0; i < n; i++) answer_type(i+1, vec[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...