結果

問題 No.5003 物理好きクリッカー
ユーザー とばりとばり
提出日時 2018-12-07 09:04:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 5,051 bytes
コンパイル時間 2,039 ms
実行使用メモリ 22,008 KB
スコア 0
平均クエリ数 2.00
最終ジャッジ日時 2021-07-19 09:03:01
合計ジャッジ時間 17,674 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: メンバ関数 ‘State State::sell(Equipment)’ 内:
main.cpp:101:5: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
  101 |     }
      |     ^

ソースコード

diff #

#include <bits/stdc++.h>

// #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<int, 5> numEquipment_;
    std::array<int, 5> 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<State, std::string> 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;
}
0