結果

問題 No.5003 物理好きクリッカー
ユーザー とばりとばり
提出日時 2018-12-07 09:10:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 393 ms / 10,000 ms
コード長 5,062 bytes
コンパイル時間 2,219 ms
実行使用メモリ 21,936 KB
スコア 23,475,183,273
平均クエリ数 10000.00
最終ジャッジ日時 2021-07-19 09:03:05
合計ジャッジ時間 15,978 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
21,672 KB
testcase_01 AC 318 ms
21,468 KB
testcase_02 AC 316 ms
21,816 KB
testcase_03 AC 316 ms
21,324 KB
testcase_04 AC 313 ms
21,828 KB
testcase_05 AC 315 ms
21,828 KB
testcase_06 AC 316 ms
21,528 KB
testcase_07 AC 316 ms
21,648 KB
testcase_08 AC 309 ms
21,660 KB
testcase_09 AC 317 ms
21,864 KB
testcase_10 AC 319 ms
21,816 KB
testcase_11 AC 313 ms
21,324 KB
testcase_12 AC 316 ms
21,672 KB
testcase_13 AC 315 ms
21,468 KB
testcase_14 AC 315 ms
21,840 KB
testcase_15 AC 319 ms
21,456 KB
testcase_16 AC 315 ms
21,936 KB
testcase_17 AC 315 ms
21,648 KB
testcase_18 AC 339 ms
21,828 KB
testcase_19 AC 393 ms
21,732 KB
testcase_20 AC 317 ms
21,504 KB
testcase_21 AC 316 ms
21,852 KB
testcase_22 AC 317 ms
21,444 KB
testcase_23 AC 318 ms
21,660 KB
testcase_24 AC 318 ms
21,360 KB
testcase_25 AC 315 ms
21,336 KB
testcase_26 AC 317 ms
21,492 KB
testcase_27 AC 318 ms
21,348 KB
testcase_28 AC 318 ms
21,324 KB
testcase_29 AC 315 ms
21,360 KB
testcase_30 AC 315 ms
21,648 KB
testcase_31 AC 321 ms
21,336 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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[] = {150, 2000, 30000, 600000, 10000000};

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