結果

問題 No.5018 Let's Make a Best-seller Book
ユーザー komori3komori3
提出日時 2024-02-24 18:01:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 400 ms
コード長 12,545 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 218,272 KB
実行使用メモリ 24,000 KB
スコア 4,377
平均クエリ数 52.00
最終ジャッジ日時 2024-02-24 18:01:45
合計ジャッジ時間 10,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,000 KB
testcase_01 AC 23 ms
24,000 KB
testcase_02 AC 22 ms
24,000 KB
testcase_03 AC 21 ms
24,000 KB
testcase_04 AC 23 ms
24,000 KB
testcase_05 AC 22 ms
24,000 KB
testcase_06 AC 23 ms
24,000 KB
testcase_07 AC 24 ms
24,000 KB
testcase_08 AC 23 ms
24,000 KB
testcase_09 AC 23 ms
24,000 KB
testcase_10 AC 23 ms
24,000 KB
testcase_11 AC 23 ms
24,000 KB
testcase_12 AC 29 ms
24,000 KB
testcase_13 AC 22 ms
24,000 KB
testcase_14 AC 22 ms
24,000 KB
testcase_15 AC 23 ms
24,000 KB
testcase_16 AC 29 ms
24,000 KB
testcase_17 AC 28 ms
24,000 KB
testcase_18 AC 51 ms
24,000 KB
testcase_19 AC 23 ms
24,000 KB
testcase_20 AC 23 ms
24,000 KB
testcase_21 AC 22 ms
24,000 KB
testcase_22 AC 23 ms
24,000 KB
testcase_23 AC 24 ms
24,000 KB
testcase_24 AC 23 ms
24,000 KB
testcase_25 AC 23 ms
24,000 KB
testcase_26 AC 34 ms
24,000 KB
testcase_27 AC 23 ms
24,000 KB
testcase_28 AC 22 ms
24,000 KB
testcase_29 AC 23 ms
24,000 KB
testcase_30 AC 24 ms
24,000 KB
testcase_31 AC 22 ms
24,000 KB
testcase_32 AC 23 ms
24,000 KB
testcase_33 AC 24 ms
24,000 KB
testcase_34 AC 24 ms
24,000 KB
testcase_35 AC 23 ms
24,000 KB
testcase_36 AC 23 ms
24,000 KB
testcase_37 AC 24 ms
24,000 KB
testcase_38 AC 22 ms
24,000 KB
testcase_39 AC 24 ms
24,000 KB
testcase_40 AC 28 ms
24,000 KB
testcase_41 AC 23 ms
24,000 KB
testcase_42 AC 24 ms
24,000 KB
testcase_43 AC 21 ms
24,000 KB
testcase_44 AC 23 ms
24,000 KB
testcase_45 AC 23 ms
24,000 KB
testcase_46 AC 28 ms
24,000 KB
testcase_47 AC 22 ms
24,000 KB
testcase_48 AC 28 ms
24,000 KB
testcase_49 AC 23 ms
24,000 KB
testcase_50 AC 35 ms
24,000 KB
testcase_51 AC 23 ms
24,000 KB
testcase_52 AC 23 ms
24,000 KB
testcase_53 AC 25 ms
24,000 KB
testcase_54 AC 24 ms
24,000 KB
testcase_55 AC 24 ms
24,000 KB
testcase_56 AC 23 ms
24,000 KB
testcase_57 AC 24 ms
24,000 KB
testcase_58 AC 23 ms
24,000 KB
testcase_59 AC 23 ms
24,000 KB
testcase_60 AC 23 ms
24,000 KB
testcase_61 AC 23 ms
24,000 KB
testcase_62 AC 23 ms
24,000 KB
testcase_63 AC 22 ms
24,000 KB
testcase_64 AC 22 ms
24,000 KB
testcase_65 AC 23 ms
24,000 KB
testcase_66 AC 23 ms
24,000 KB
testcase_67 AC 29 ms
24,000 KB
testcase_68 AC 22 ms
24,000 KB
testcase_69 AC 23 ms
24,000 KB
testcase_70 AC 22 ms
24,000 KB
testcase_71 AC 22 ms
24,000 KB
testcase_72 AC 22 ms
24,000 KB
testcase_73 AC 24 ms
24,000 KB
testcase_74 AC 26 ms
24,000 KB
testcase_75 AC 23 ms
24,000 KB
testcase_76 AC 25 ms
24,000 KB
testcase_77 AC 23 ms
24,000 KB
testcase_78 AC 23 ms
24,000 KB
testcase_79 AC 29 ms
24,000 KB
testcase_80 AC 23 ms
24,000 KB
testcase_81 AC 24 ms
24,000 KB
testcase_82 AC 23 ms
24,000 KB
testcase_83 AC 22 ms
24,000 KB
testcase_84 AC 22 ms
24,000 KB
testcase_85 AC 42 ms
24,000 KB
testcase_86 AC 23 ms
24,000 KB
testcase_87 AC 22 ms
24,000 KB
testcase_88 AC 24 ms
24,000 KB
testcase_89 AC 23 ms
24,000 KB
testcase_90 AC 24 ms
24,000 KB
testcase_91 AC 54 ms
24,000 KB
testcase_92 AC 23 ms
24,000 KB
testcase_93 AC 23 ms
24,000 KB
testcase_94 AC 24 ms
24,000 KB
testcase_95 AC 28 ms
24,000 KB
testcase_96 AC 23 ms
24,000 KB
testcase_97 AC 22 ms
24,000 KB
testcase_98 AC 23 ms
24,000 KB
testcase_99 AC 23 ms
24,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_NONSTDC_NO_WARNINGS
#define _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING
#include <bits/stdc++.h>
#include <random>
#include <unordered_set>
#include <array>
#include <optional>
#ifdef _MSC_VER
#include <opencv2/core.hpp>
#include <opencv2/core/utils/logger.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <conio.h>
#include <ppl.h>
#include <omp.h>
#include <filesystem>
#include <intrin.h>
/* g++ functions */
int __builtin_clz(unsigned int n) { unsigned long index; _BitScanReverse(&index, n); return 31 - index; }
int __builtin_ctz(unsigned int n) { unsigned long index; _BitScanForward(&index, n); return index; }
namespace std { inline int __lg(int __n) { return sizeof(int) * 8 - 1 - __builtin_clz(__n); } }
int __builtin_popcount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
/* enable __uint128_t in MSVC */
//#include <boost/multiprecision/cpp_int.hpp>
//using __uint128_t = boost::multiprecision::uint128_t;
#else
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

/** compro io **/
namespace aux {
    template<typename T, unsigned N, unsigned L> struct tp { static void output(std::ostream& os, const T& v) { os << std::get<N>(v) << ", "; tp<T, N + 1, L>::output(os, v); } };
    template<typename T, unsigned N> struct tp<T, N, N> { static void output(std::ostream& os, const T& v) { os << std::get<N>(v); } };
}
template<typename... Ts> std::ostream& operator<<(std::ostream& os, const std::tuple<Ts...>& t) { os << '{'; aux::tp<std::tuple<Ts...>, 0, sizeof...(Ts) - 1>::output(os, t); return os << '}'; } // tuple out
template<class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& os, const Container& x); // container out (fwd decl)
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) { return os << '{' << p.first << ", " << p.second << '}'; } // pair out
template<class S, class T> std::istream& operator>>(std::istream& is, std::pair<S, T>& p) { return is >> p.first >> p.second; } // pair in
std::ostream& operator<<(std::ostream& os, const std::vector<bool>::reference& v) { os << (v ? '1' : '0'); return os; } // bool (vector) out
std::ostream& operator<<(std::ostream& os, const std::vector<bool>& v) { bool f = true; os << '{'; for (const auto& x : v) { os << (f ? "" : ", ") << x; f = false; } os << '}'; return os; } // vector<bool> out
template<class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& os, const Container& x) { bool f = true; os << '{'; for (auto& y : x) { os << (f ? "" : ", ") << y; f = false; } return os << '}'; } // container out
template<class T, class = decltype(std::begin(std::declval<T&>())), class = typename std::enable_if<!std::is_same<T, std::string>::value>::type> std::istream& operator>>(std::istream& is, T& a) { for (auto& x : a) is >> x; return is; } // container in
template<typename T> auto operator<<(std::ostream& out, const T& t) -> decltype(out << t.stringify()) { out << t.stringify(); return out; } // struct (has stringify() func) out
/** io setup **/
struct IOSetup { IOSetup(bool f) { if (f) { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } std::cout << std::fixed << std::setprecision(15); } }
iosetup(true); // set false when solving interective problems
/** string formatter **/
template<typename... Ts> std::string format(const std::string& f, Ts... t) { size_t l = std::snprintf(nullptr, 0, f.c_str(), t...); std::vector<char> b(l + 1); std::snprintf(&b[0], l + 1, f.c_str(), t...); return std::string(&b[0], &b[0] + l); }
/** dump **/
#define DUMPOUT std::cerr
std::ostringstream DUMPBUF;
#define dump(...) do{DUMPBUF<<"  ";DUMPBUF<<#__VA_ARGS__<<" :[DUMP - "<<__LINE__<<":"<<__FUNCTION__<<']'<<std::endl;DUMPBUF<<"    ";dump_func(__VA_ARGS__);DUMPOUT<<DUMPBUF.str();DUMPBUF.str("");DUMPBUF.clear();}while(0);
void dump_func() { DUMPBUF << std::endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPBUF << head; if (sizeof...(Tail) == 0) { DUMPBUF << " "; } else { DUMPBUF << ", "; } dump_func(std::move(tail)...); }
/** timer **/
class Timer {
    double t = 0, paused = 0, tmp;
public:
    Timer() { reset(); }
    static double time() {
#ifdef _MSC_VER
        return __rdtsc() / 2.9e9;
#else
        unsigned long long a, d;
        __asm__ volatile("rdtsc"
            : "=a"(a), "=d"(d));
        return (d << 32 | a) / 2.9e9;
#endif
    }
    void reset() { t = time(); }
    void pause() { tmp = time(); }
    void restart() { paused += time() - tmp; }
    double elapsed_ms() const { return (time() - t - paused) * 1000.0; }
};
/** rand **/
struct Xorshift {
    Xorshift() {}
    Xorshift(uint64_t seed) { reseed(seed); }
    inline void reseed(uint64_t seed) { x = 0x498b3bc5 ^ seed; for (int i = 0; i < 20; i++) next_u64(); }
    inline uint64_t next_u64() { x ^= x << 7; return x ^= x >> 9; }
    inline uint32_t next_u32() { return next_u64() >> 32; }
    inline uint32_t next_u32(uint32_t mod) { return ((uint64_t)next_u32() * mod) >> 32; }
    inline uint32_t next_u32(uint32_t l, uint32_t r) { return l + next_u32(r - l + 1); }
    inline double next_double() { return next_u32() * e; }
    inline double next_double(double c) { return next_double() * c; }
    inline double next_double(double l, double r) { return next_double(r - l) + l; }
private:
    static constexpr uint32_t M = UINT_MAX;
    static constexpr double e = 1.0 / M;
    uint64_t x = 88172645463325252LL;
};
/** shuffle **/
template<typename T> void shuffle_vector(std::vector<T>& v, Xorshift& rnd) { int n = v.size(); for (int i = n - 1; i >= 1; i--) { int r = rnd.next_u32(i); std::swap(v[i], v[r]); } }
/** split **/
std::vector<std::string> split(const std::string& str, const std::string& delim) {
    std::vector<std::string> res;
    std::string buf;
    for (const auto& c : str) {
        if (delim.find(c) != std::string::npos) {
            if (!buf.empty()) res.push_back(buf);
            buf.clear();
        }
        else buf += c;
    }
    if (!buf.empty()) res.push_back(buf);
    return res;
}
std::string join(const std::string& delim, const std::vector<std::string>& elems) {
    if (elems.empty()) return "";
    std::string res = elems[0];
    for (int i = 1; i < (int)elems.size(); i++) {
        res += delim + elems[i];
    }
    return res;
}
/** misc **/
template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } // fill array
template<typename T, typename ...Args> auto make_vector(T x, int arg, Args ...args) { if constexpr (sizeof...(args) == 0)return std::vector<T>(arg, x); else return std::vector(arg, make_vector<T>(x, args...)); }
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
/** hash **/
namespace aux { template<typename T> inline void hash(std::size_t& s, const T& v) { s ^= std::hash<T>()(v) + 0x9e3779b9 + (s << 6) + (s >> 2); } }
namespace std { template<typename F, typename S> struct hash<std::pair<F, S>> { size_t operator()(const std::pair<F, S>& s) const noexcept { size_t seed = 0; aux::hash(seed, s.first); aux::hash(seed, s.second); return seed; } }; }

/* fast queue */
class FastQueue {
    int front = 0;
    int back = 0;
    int v[4096];
public:
    inline bool empty() { return front == back; }
    inline void push(int x) { v[front++] = x; }
    inline int pop() { return v[back++]; }
    inline void reset() { front = back = 0; }
    inline int size() { return front - back; }
};

class RandomQueue {
    int sz = 0;
    int v[4096];
public:
    inline bool empty() const { return !sz; }
    inline int size() const { return sz; }
    inline void push(int x) { v[sz++] = x; }
    inline void reset() { sz = 0; }
    inline int pop(int i) {
        std::swap(v[i], v[sz - 1]);
        return v[--sz];
    }
    inline int pop(Xorshift& rnd) {
        return pop(rnd.next_u32(sz));
    }
};

#if 1
inline double get_temp(double stemp, double etemp, double t, double T) {
    return etemp + (stemp - etemp) * (T - t) / T;
};
#else
inline double get_temp(double stemp, double etemp, double t, double T) {
    return stemp * pow(etemp / stemp, t / T);
};
#endif

struct LogTable {
    static constexpr int M = 65536;
    static constexpr int mask = M - 1;
    double l[M];
    LogTable() : l() {
        unsigned long long x = 88172645463325252ULL;
        double log_u64max = log(2) * 64;
        for (int i = 0; i < M; i++) {
            x = x ^ (x << 7);
            x = x ^ (x >> 9);
            l[i] = log(double(x)) - log_u64max;
        }
    }
    inline double operator[](int i) const { return l[i & mask]; }
} log_table;



constexpr int T = 52;
constexpr int N = 10;
constexpr int INITIAL_MONEY = 2000000;

struct HiddenInput {

    const std::array<double, N> D;
    const std::array<std::array<double, N>, T> Z;

    static HiddenInput create(std::istream& in) {

        std::array<double, N> D;
        std::array<std::array<double, N>, T> Z;

        in >> D[0] >> D[0]; // ignore N, T
        in >> D >> Z;

        return HiddenInput(D, Z);
    }

private:

    HiddenInput(
        const std::array<double, N> D_,
        const std::array<std::array<double, N>, T> Z_
    ) : D(D_), Z(Z_) {}

};



struct Result {
    int money;
    std::array<int, N> S;
    std::array<int, N> P;
    std::array<int, N> R;
};

struct Tester;
using TesterPtr = std::shared_ptr<Tester>;
struct Tester {

    virtual Result query(const std::array<int, N>& L) = 0;
    virtual Result query(const int x) = 0;

};

struct ServerTester;
using ServerTesterPtr = std::shared_ptr<ServerTester>;
struct ServerTester : Tester {

    Result receive_result() {
        Result res;
        in >> res.money;
        assert(res.money != -1);
        in >> res.S >> res.P >> res.R;
        return res;
    }

    Result query(const std::array<int, N>& L) override {

        out << 1;
        for (int i = 0; i < N; i++) {
            out << ' ' << L[i];
        }
        out << std::endl;

        return receive_result();
    }

    Result query(const int x) override {

        out << 2 << ' ' << x << std::endl;

        return receive_result();
    }

    static ServerTesterPtr create(std::istream& in, std::ostream& out) {
        return std::make_shared<ServerTester>(ServerTester(in, out));
    }

private:

    std::istream& in;
    std::ostream& out;

    ServerTester(std::istream& in_, std::ostream& out_) : in(in_), out(out_) {
        int buf;
        in >> buf >> buf >> buf; // ignore T, N, Money
    }

};

struct FileTester;
using FileTesterPtr = std::shared_ptr<FileTester>;
struct FileTester : Tester {

    const HiddenInput hinput;

    Result query(const std::array<int, N>& L) override {
        return {};
    }

    Result query(const int x) override {
        return {};
    }

    static FileTesterPtr create(std::istream& in, std::ostream& out) {
        const auto hinput = HiddenInput::create(in);
        return std::make_shared<FileTester>(FileTester(hinput, out));
    }

private:

    std::ostream& out;
    std::string ans;

    FileTester(const HiddenInput& hinput_, std::ostream& out_)
        : hinput(hinput_), out(out_) {}

};



int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {

    Timer timer;

#ifdef HAVE_OPENCV_HIGHGUI
    cv::utils::logging::setLogLevel(cv::utils::logging::LogLevel::LOG_LEVEL_SILENT);
#endif

#if 0
    std::ifstream ifs("../../tools/in/seed_0001.txt");
    std::istream& in = ifs;
    std::ofstream ofs("../../tools/out/seed_0001.txt");
    std::ostream& out = ofs;
    //auto tester = FileTester::create(in, out);
#else
    std::istream& in = std::cin;
    std::ostream& out = std::cout;
    auto tester = ServerTester::create(in, out);
#endif

    int Money = INITIAL_MONEY;
    std::array<int, N> L{};

    using namespace std;

    // インタラクティブ開始
    for (int t = 1; t <= T; t++) {
        for (int i = 0; i < N; i++) L[i] = Money / (500 * N);
        auto res = tester->query(L);
        Money = res.money;
    }

    return 0;
}
0