結果

問題 No.5003 物理好きクリッカー
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2018-12-08 11:31:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 780 ms / 10,000 ms
コード長 10,054 bytes
コンパイル時間 1,924 ms
実行使用メモリ 66,272 KB
スコア 56,997,261,793
平均クエリ数 10000.00
最終ジャッジ日時 2021-07-19 09:10:25
合計ジャッジ時間 30,126 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 710 ms
61,968 KB
testcase_01 AC 697 ms
61,348 KB
testcase_02 AC 766 ms
61,952 KB
testcase_03 AC 709 ms
61,608 KB
testcase_04 AC 700 ms
61,752 KB
testcase_05 AC 745 ms
61,748 KB
testcase_06 AC 705 ms
61,448 KB
testcase_07 AC 705 ms
61,672 KB
testcase_08 AC 711 ms
61,700 KB
testcase_09 AC 772 ms
61,652 KB
testcase_10 AC 703 ms
61,948 KB
testcase_11 AC 700 ms
61,572 KB
testcase_12 AC 779 ms
61,928 KB
testcase_13 AC 707 ms
61,632 KB
testcase_14 AC 710 ms
61,592 KB
testcase_15 AC 718 ms
61,508 KB
testcase_16 AC 730 ms
61,600 KB
testcase_17 AC 751 ms
61,668 KB
testcase_18 AC 700 ms
61,756 KB
testcase_19 AC 700 ms
61,664 KB
testcase_20 AC 741 ms
61,536 KB
testcase_21 AC 732 ms
61,400 KB
testcase_22 AC 706 ms
61,604 KB
testcase_23 AC 704 ms
61,556 KB
testcase_24 AC 780 ms
61,840 KB
testcase_25 AC 709 ms
61,484 KB
testcase_26 AC 705 ms
61,412 KB
testcase_27 AC 733 ms
61,652 KB
testcase_28 AC 724 ms
61,416 KB
testcase_29 AC 742 ms
61,896 KB
testcase_30 AC 698 ms
61,716 KB
testcase_31 AC 771 ms
61,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    static final XorShift rng = new XorShift(System.nanoTime());
    static final Watch watch = new Watch();
    private SAState sa = new SAState();

    private long numCookies;

    private int turn = -1;

    private long add = 1;
    private long price = 15;
    private int count = 1;
    private int reinforce = 0;
    private String[] names = new String[] { "hand", "lily", "factory", "casino", "grimoire", };
    private long[] adds = new long[] { 1, 10, 120, 2000, 25000, };
    private long[] prices = new long[] { 150, 2000, 30000, 600000, 10000000, };
    private int[] counts = new int[] { 0, 0, 0, 0, 0, };
    private int[] reinforces = new int[] { 0, 0, 0, 0, 0, };
    private boolean isSale;
    private int fever;

    private long buyPrice(int index) {
        if (index < 0) {
            long p = price;
            return p;
        }
        long p = prices[index];
        for (int i = 0; i < counts[index]; i++) {
            p = (long) Math.ceil((p * 6) / 5);
        }
        return p;
    }

    private long reinforcePrice(int index) {
        if (index < 0) {
            long p = price;
            for (int i = 0; i < reinforce; i++) {
                p *= 10;
            }
            return p;
        }
        long p = prices[index];
        for (int i = 0; i < reinforces[index]; i++) {
            p *= 10;
        }
        return p;
    }

    private void solve(String S) {
        turn++;
        long prevNumCookies = numCookies;
        String command = "click";
        int index = -1;

//        if (turn < 8500) 
        long rp = (long) ((isSale ? 0.9 : 1) * reinforcePrice(-1));
        {
            double d = 1.0;
            if (numCookies >= rp) {
                if ((10000 - turn) * (add * (1L << (reinforce + 1))) - rp > d * (10000 - turn) * (add * (1L << reinforce))) {
                    command = "enhclick";
                    index = -1;
                }
            }

            for (int i = prices.length - 1; i >= 0; i--) {
                long bp = (long) ((isSale ? 0.9 : 1) * buyPrice(i));
                if (numCookies < bp) {
                    continue;
                }
                long cookie = cookiesWithOutFever();
                counts[i]++;
                long cookieBuy = cookiesWithOutFever();
                counts[i]--;
                if ((10000 - turn) * cookieBuy - bp < d * (10000 - turn) * cookie) {
                    continue;
                }
                command = "buy";
                index = i;
            }

            for (int i = prices.length - 1; i >= 0; i--) {
                long rp2 = (long) ((isSale ? 0.9 : 1) * reinforcePrice(i));
                if (numCookies < rp2) {
                    continue;
                }
                if (counts[i] <= 0) {
                    continue;
                }
                long cookie = cookiesWithOutFever();
                reinforces[i]++;
                long cookieReinforce = cookiesWithOutFever();
                reinforces[i]--;
                if ((10000 - turn) * cookieReinforce - rp2 < d * (10000 - turn) * cookie) {
                    continue;
                }

                command = "reinforce";
                index = i;
            }
        }
//        numCookies -= price[i];
//        count[i]++;

        if (command.equals("click")) {
            numCookies += (fever > 0 ? 7 : 1) * add * (1L << reinforce);
        } else if (command.equals("enhclick")) {
            numCookies -= rp;
            reinforce++;
        } else if (command.equals("buy")) {
            numCookies -= (long) ((isSale ? 0.9 : 1) * buyPrice(index));
            if (index < 0) {
                count++;
            } else {
                counts[index]++;
            }
        } else if (command.equals("reinforce")) {
            numCookies -= (long) ((isSale ? 0.9 : 1) * reinforcePrice(index));
            reinforces[index]++;
        }

        numCookies += cookies();

        isSale = false;
        if (fever > 0) {
            fever--;
        }

        if (S.equals("B")) {
            numCookies += (long) (0.01 * numCookies);
        } else if (S.equals("S")) {
            isSale = true;
        } else if (S.equals("F")) {
            fever = 20;
        }

        if (!command.equals("click") || turn >= 9998) {
            Utils.debug(turn, "numCookies", prevNumCookies, numCookies, "cookie", cookies(), "command", command + (index >= 0 ? " " + index : ""));
        }
        System.out.println(command + (index >= 0 ? " " + names[index] : ""));
        System.out.flush();
    }

    private long cookies() {
        long cookie = 0;
        for (int i = 0; i < adds.length; i++) {
            cookie += (fever > 0 ? 7 : 1) * adds[i] * counts[i] * (1L << reinforces[i]);
        }
        return cookie;
    }

    private long cookiesWithOutFever() {
        long cookie = 0;
        for (int i = 0; i < adds.length; i++) {
            cookie += adds[i] * counts[i] * (1L << reinforces[i]);
        }
        return cookie;
    }

    public void run() {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(in.readLine());
            for (int i = 0; i < N; i++) {
                String S = in.readLine();
                solve(S);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        new Main().run();
    }
}

class SAState {

    public static final boolean useTime = true;

    public double startTime = 0;
    public double endTime = 10 * 10 * 10;
    public double time = startTime;

    public double startTemperature = 100;
    public double endTemperature = 0;
    public double inverseTemperature = 1.0 / startTemperature;
    public double lastAcceptTemperature = startTemperature;

    public double startRange = 1;
    public double endRange = 1e4;
    public double range = startRange;

    public int numIterations;
    public int validIterations;
    public int acceptIterations;

    public void init() {
        numIterations = 0;
        validIterations = 0;
        acceptIterations = 0;

        startTime = useTime ? Main.watch.getSecond() : numIterations;

        update();
        lastAcceptTemperature = inverseTemperature;
    }

    public void update() {
        updateTime();
        updateTemperature();
        updateRange();
    }

    public void updateTemperature() {
        inverseTemperature = 1.0 / (endTemperature + (startTemperature - endTemperature) * Math.pow((endTime - time) / (endTime - startTime), 1.0));
    }

    public void updateRange() {
        range = endRange + (startRange - endRange) * Math.pow((endTime - time) / (endTime - startTime), 1.0);
    }

    public void updateTime() {
        time = useTime ? Main.watch.getSecond() : numIterations;
    }

    public boolean isTLE() {
        return time >= endTime;
    }

    public boolean accept(double deltaScore) {
        return acceptS(deltaScore);
    }

    public boolean acceptB(double deltaScore) {
        validIterations++;

        if (deltaScore > -1e-9) {
            acceptIterations++;
            return true;
        }

        assert deltaScore < 0;
        assert 1.0 / inverseTemperature >= 0;

        if (deltaScore * inverseTemperature < -10) {
            return false;
        }

        if (Main.rng.nextDouble() < Math.exp(deltaScore * inverseTemperature)) {
            acceptIterations++;
            lastAcceptTemperature = inverseTemperature;
            return true;
        }
        return false;
    }

    public boolean acceptS(double deltaScore) {
        validIterations++;

        if (deltaScore < 1e-9) {
            acceptIterations++;
            return true;
        }

        assert deltaScore > 0;
        assert 1.0 / inverseTemperature >= 0;

        if (-deltaScore * inverseTemperature < -10) {
            return false;
        }

        if (Main.rng.nextDouble() < Math.exp(-deltaScore * inverseTemperature)) {
            acceptIterations++;
            lastAcceptTemperature = inverseTemperature;
            return true;
        }
        return false;
    }

}

final class Utils {
    private Utils() {
    }

    public static final void debug(Object... o) {
        System.err.println(toString(o));
    }

    public static final String toString(Object... o) {
        return Arrays.deepToString(o);
    }

}

class Watch {
    private long start;

    public Watch() {
        init();
    }

    public double getSecond() {
        return (System.nanoTime() - start) * 1e-9;
    }

    public void init() {
        init(System.nanoTime());
    }

    private void init(long start) {
        this.start = start;
    }

    public String getSecondString() {
        return toString(getSecond());
    }

    public static final String toString(double second) {
        if (second < 60) {
            return String.format("%5.2fs", second);
        } else if (second < 60 * 60) {
            int minute = (int) (second / 60);
            return String.format("%2dm%2ds", minute, (int) (second % 60));
        } else {
            int hour = (int) (second / (60 * 60));
            int minute = (int) (second / 60);
            return String.format("%2dh%2dm%2ds", hour, minute % (60), (int) (second % 60));
        }
    }

}

class XorShift {
    private int w = 88675123;
    private int x = 123456789;
    private int y = 362436069;
    private int z = 521288629;

    public XorShift(long l) {
        x = (int) l;
    }

    public int nextInt() {
        final int t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        w = w ^ (w >>> 19) ^ (t ^ (t >>> 8));
        return w;
    }

    public double nextDouble() {
        return (nextInt() >>> 1) * 4.6566128730773926E-10;
    }

    public int nextInt(int n) {
        return (int) (n * nextDouble());
    }

}
0