#include // #define DEBUG const int64_t inf = (1LL << 50); enum Equipment { HAND, LILY, FACTORY, CASINO, GRIMOIRE }; const Equipment equipments[] = {HAND, LILY, FACTORY, CASINO, GRIMOIRE}; const std::string names[] = {"hand", "lily", "factory", "casino", "grimoire"}; const int64_t baseProductivities[] = {1, 10, 120, 2000, 25000}; const int64_t basePrices[] = {1, 10, 120, 2000, 25000}; int64_t productivity(Equipment e, int level) { return (baseProductivities[e] << level); } int64_t reinforcePrice(Equipment e, int level) { int64_t res = basePrices[e]; for (int i = 0; i <= level; i++) { res *= 10; } return res; } int64_t buyPrice(Equipment e, int num) { int64_t res = basePrices[e]; for (int i = 0; i < num; i++) { res = (6 * res + 4) / 5; } return res; } struct State { int turn_; int64_t score_; int levelClick_; std::array numEquipment_; std::array levelEquipment_; State(): turn_{0}, score_{0}, levelClick_{0} { numEquipment_.fill(0); levelEquipment_.fill(0); } void produce() { if (score_ < 0) return; for (auto e : equipments) { score_ += numEquipment_[e] * productivity(e, levelEquipment_[e]); } } void update() { if (score_ < 0) { score_ = -inf; } produce(); turn_++; } State click() const { State next = *this; next.score_ += (1LL << levelClick_); next.update(); return next; } State buy(Equipment e) const { State next = *this; next.score_ -= buyPrice(e, numEquipment_[e]); next.numEquipment_[e]++; next.update(); return next; } // 未実装 State sell(Equipment e) { } State reinforce(Equipment e) const { State next = *this; next.score_ -= reinforcePrice(e, levelEquipment_[e]); next.levelEquipment_[e]++; next.update(); return next; } State enhclick() const { State next = *this; int64_t cost = 15; for (int i = 0; i < levelClick_; i++) { cost *= 10; } next.score_ -= cost; next.levelClick_++; next.update(); return next; } int64_t expectScore(int numTurn) { if (score_ < 0) return -inf; int64_t add = (1LL << levelClick_); for (auto e : equipments) { add += numEquipment_[e] * productivity(e, levelEquipment_[e]); } return score_ + numTurn * add; } }; std::pair findNextAction(const State& current, int numTurn) { int64_t bestScore = 0; std::string action = "click"; State next = current; // click { State click = current.click(); int64_t score = click.expectScore(numTurn - 1); if (score > bestScore) { next = click; bestScore = score; action = "click"; } } // enhclick { State enhclick = current.enhclick(); int64_t score = enhclick.expectScore(numTurn - 1); if (score > bestScore) { next = enhclick; bestScore = score; action = "enhclick"; } } // buy { for (auto e : equipments) { State buy = current.buy(e); int64_t score = buy.expectScore(numTurn - 1); if (score > bestScore) { next = buy; bestScore = score; action = "buy " + names[e]; } } } // reinforce { for (auto e : equipments) { State reinforce = current.reinforce(e); int64_t score = reinforce.expectScore(numTurn - 1); if (score > bestScore) { next = reinforce; bestScore = score; action = "reinforce " + names[e]; } } } return {next, action}; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int n; std::cin >> n; std::string s; std::cin >> s; State current{}; for (int i = 0; i < n; i++) { auto result = findNextAction(current, n - i); std::cout << result.second << std::endl; std::string response; std::cin >> response; assert(response == "ok"); current = result.first; #ifdef DEBUG std::cerr << "====== " << i << " ======" << std::endl; std::cerr << "score " << current.score_ << std::endl; #endif } #ifdef DEBUG std::cerr << "[Score] " << current.expectScore(0) << std::endl; for (auto e : equipments) { std::cerr << "[" << names[e] << "] " << current.numEquipment_[e] << ", " << current.levelEquipment_[e] << std::endl; } #endif return 0; }