結果

問題 No.5004 Room Assignment
ユーザー komori3komori3
提出日時 2021-12-01 20:22:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 5,000 ms
コード長 10,035 bytes
コンパイル時間 2,882 ms
実行使用メモリ 22,368 KB
スコア 137,105,513
平均クエリ数 7642.18
最終ジャッジ日時 2021-12-01 20:22:29
合計ジャッジ時間 23,924 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
21,936 KB
testcase_01 AC 135 ms
21,924 KB
testcase_02 AC 139 ms
21,912 KB
testcase_03 AC 140 ms
22,332 KB
testcase_04 AC 135 ms
21,792 KB
testcase_05 AC 134 ms
21,792 KB
testcase_06 AC 133 ms
22,164 KB
testcase_07 AC 134 ms
21,996 KB
testcase_08 AC 133 ms
21,936 KB
testcase_09 AC 134 ms
21,756 KB
testcase_10 AC 134 ms
21,924 KB
testcase_11 AC 141 ms
21,888 KB
testcase_12 AC 139 ms
21,972 KB
testcase_13 AC 136 ms
21,936 KB
testcase_14 AC 133 ms
22,152 KB
testcase_15 AC 137 ms
21,948 KB
testcase_16 AC 135 ms
21,936 KB
testcase_17 AC 138 ms
22,140 KB
testcase_18 AC 134 ms
21,924 KB
testcase_19 AC 134 ms
21,972 KB
testcase_20 AC 137 ms
21,996 KB
testcase_21 AC 139 ms
21,984 KB
testcase_22 AC 134 ms
21,888 KB
testcase_23 AC 134 ms
22,188 KB
testcase_24 AC 133 ms
22,140 KB
testcase_25 AC 134 ms
21,864 KB
testcase_26 AC 136 ms
22,092 KB
testcase_27 AC 135 ms
22,188 KB
testcase_28 AC 135 ms
22,092 KB
testcase_29 AC 137 ms
22,356 KB
testcase_30 AC 139 ms
21,948 KB
testcase_31 AC 133 ms
21,780 KB
testcase_32 AC 135 ms
21,764 KB
testcase_33 AC 135 ms
22,140 KB
testcase_34 AC 134 ms
21,792 KB
testcase_35 AC 136 ms
22,152 KB
testcase_36 AC 137 ms
21,888 KB
testcase_37 AC 136 ms
21,780 KB
testcase_38 AC 138 ms
21,920 KB
testcase_39 AC 138 ms
21,984 KB
testcase_40 AC 135 ms
22,092 KB
testcase_41 AC 134 ms
21,924 KB
testcase_42 AC 132 ms
21,972 KB
testcase_43 AC 135 ms
21,612 KB
testcase_44 AC 134 ms
22,344 KB
testcase_45 AC 135 ms
21,936 KB
testcase_46 AC 134 ms
22,008 KB
testcase_47 AC 135 ms
21,900 KB
testcase_48 AC 139 ms
21,780 KB
testcase_49 AC 134 ms
21,944 KB
testcase_50 AC 134 ms
21,972 KB
testcase_51 AC 133 ms
22,164 KB
testcase_52 AC 135 ms
21,936 KB
testcase_53 AC 133 ms
21,792 KB
testcase_54 AC 135 ms
22,092 KB
testcase_55 AC 135 ms
21,960 KB
testcase_56 AC 136 ms
22,140 KB
testcase_57 AC 138 ms
22,092 KB
testcase_58 AC 136 ms
22,368 KB
testcase_59 AC 135 ms
21,768 KB
testcase_60 AC 133 ms
22,128 KB
testcase_61 AC 132 ms
21,912 KB
testcase_62 AC 133 ms
21,924 KB
testcase_63 AC 133 ms
22,128 KB
testcase_64 AC 134 ms
21,924 KB
testcase_65 AC 134 ms
21,948 KB
testcase_66 AC 137 ms
21,936 KB
testcase_67 AC 133 ms
21,924 KB
testcase_68 AC 134 ms
21,768 KB
testcase_69 AC 133 ms
21,888 KB
testcase_70 AC 135 ms
22,212 KB
testcase_71 AC 134 ms
21,948 KB
testcase_72 AC 134 ms
22,080 KB
testcase_73 AC 136 ms
22,356 KB
testcase_74 AC 135 ms
21,936 KB
testcase_75 AC 139 ms
21,972 KB
testcase_76 AC 135 ms
22,104 KB
testcase_77 AC 133 ms
21,960 KB
testcase_78 AC 134 ms
21,912 KB
testcase_79 AC 133 ms
21,792 KB
testcase_80 AC 133 ms
22,200 KB
testcase_81 AC 135 ms
22,152 KB
testcase_82 AC 137 ms
21,792 KB
testcase_83 AC 135 ms
21,792 KB
testcase_84 AC 141 ms
22,164 KB
testcase_85 AC 140 ms
21,924 KB
testcase_86 AC 135 ms
21,804 KB
testcase_87 AC 136 ms
21,888 KB
testcase_88 AC 134 ms
21,924 KB
testcase_89 AC 134 ms
21,888 KB
testcase_90 AC 135 ms
21,972 KB
testcase_91 AC 134 ms
21,924 KB
testcase_92 AC 134 ms
21,924 KB
testcase_93 AC 147 ms
21,876 KB
testcase_94 AC 134 ms
21,876 KB
testcase_95 AC 134 ms
22,188 KB
testcase_96 AC 133 ms
21,936 KB
testcase_97 AC 133 ms
21,996 KB
testcase_98 AC 135 ms
21,888 KB
testcase_99 AC 134 ms
21,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef _MSC_VER
#include <ppl.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#else
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

/** compro_io **/

/* tuple */
// out
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 << ']';
}

/* pair */
// out
template<class S, class T>
std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
    return os << "[" << p.first << ", " << p.second << "]";
}
// in
template<class S, class T>
std::istream& operator>>(std::istream& is, const std::pair<S, T>& p) {
    return is >> p.first >> p.second;
}

/* container */
// 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 << "]";
}
// in
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;
}

/* struct */
template<typename T>
auto operator<<(std::ostream& out, const T& t) -> decltype(out << t.stringify()) {
    out << t.stringify();
    return out;
}

/* 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);

/** 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);
}

template<typename T>
std::string stringify(const T& x) {
    std::ostringstream oss;
    oss << x;
    return oss.str();
}

/** logger **/
// yyyy-MM-dd hh:mm:ss.xxx [LOGLEVEL] [MESSAGE] @[FILE]:[FUNCTION]:L[LINE]
struct SLogger {

private:

    const char* cc_reset = "\x1b[0m";
    const char* cc_color[4] = { "", "\x1b[42m", "\x1b[43m", "\x1b[41m" };
    const char* levelstr[4] = { "[DEBUG]", "[INFO ]", "[WARN ]", "[ERROR]" };

    std::ostream& out;
    const char* called_file;
    const int called_line;
    const bool is_stream;
    int log_level;

#ifdef _MSC_VER
    std::string get_now_time() {
        static constexpr size_t len = sizeof("2021-01-31 23:59:59.000");
        static char tstr[len];
        auto now = std::chrono::system_clock::now();
        auto duration = now.time_since_epoch();
        auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
        auto sec = msec / 1000;
        strftime(tstr, len, "%Y-%m-%d %H:%M:%S", localtime(&sec));
        int delta = (int)(msec - (sec * 1000));
        snprintf(tstr, len, "%s.%03d", tstr, delta);
        return std::string(tstr, tstr + len);
    }
#else 
    std::string get_now_time() {
        static constexpr size_t len = sizeof("2021-01-31 23:59:59.000");
        static char tstr[len - 4];
        static char res[len];
        static timespec ts;
        static tm t;
        clock_gettime(CLOCK_REALTIME, &ts);
        localtime_r(&ts.tv_sec, &t);
        strftime(tstr, len - 4, "%Y-%m-%d %H:%M:%S", &t);
        const int msec = ts.tv_nsec / 1000000;
        snprintf(res, len, "%s.%03d", tstr, msec);
        return std::string(res, res + len);
    }
#endif

public:

    SLogger(std::ostream& out, const char* called_file, int called_line) :
        out(out), called_file(called_file), called_line(called_line),
        is_stream(out.rdbuf() == std::cout.rdbuf() || out.rdbuf() == std::cerr.rdbuf()),
        log_level(0)
    {
        log(1, called_file, "", called_line, "logging start.");
    }

    ~SLogger() {
        log(1, called_file, "", called_line, "logging end.");
    }

    inline void set_log_level(int level) { log_level = level; }

    template<typename... Ts>
    void log(int level, const char* file, const char* func, int line, const std::string& f, Ts... t) {
        if (level < log_level) return;
        out << get_now_time() << ' '
            << (is_stream ? cc_color[level] : "")
            << levelstr[level]
            << (is_stream ? cc_reset : "") << ' '
            << format(f, t...) << "\t\t@"
            << file << ':' << func << ":L"
            << line
            << std::endl;
    }

};

#define DEBUG(msg, ...) logger.log(0, __FILE__, __FUNCTION__, __LINE__, msg, __VA_ARGS__)
#define  INFO(msg, ...) logger.log(1, __FILE__, __FUNCTION__, __LINE__, msg, __VA_ARGS__)
#define  WARN(msg, ...) logger.log(2, __FILE__, __FUNCTION__, __LINE__, msg, __VA_ARGS__)
#define ERROR(msg, ...) logger.log(3, __FILE__, __FUNCTION__, __LINE__, msg, __VA_ARGS__)

#define SET_LOGGER(stream) namespace { SLogger logger(stream, __FILE__, __LINE__); }

// Prevent logger redefinition when merging into a single file.
#ifndef LOGGER_9FF580DD_E170_4A26_BE9E_E2F40C5DE992
#define LOGGER_9FF580DD_E170_4A26_BE9E_E2F40C5DE992
SET_LOGGER(std::cerr);
#endif

/* dump */
#define ENABLE_DUMP
#ifdef ENABLE_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)...); }
#else
#define dump(...) void(0);
#endif

/* timer */
class Timer {
    double t = 0, paused = 0, tmp;
public:
    Timer() { reset(); }
    static double time() {
#ifdef _MSC_VER
        return __rdtsc() / 3.0e9;
#else
        unsigned long long a, d;
        __asm__ volatile("rdtsc"
            : "=a"(a), "=d"(d));
        return (d << 32 | a) / 3.0e9;
#endif
    }
    void reset() { t = time(); }
    void pause() { tmp = time(); }
    void restart() { paused += time() - tmp; }
    double elapsed_ms() { return (time() - t - paused) * 1000.0; }
} timer;

/* rand */
struct Xorshift {
    uint64_t x = 88172645463325252LL;
    void set_seed(unsigned seed, int rep = 100) { x = uint64_t((seed + 1) * 10007); for (int i = 0; i < rep; i++) next_int(); }
    unsigned next_int() { x = x ^ (x << 7); return x = x ^ (x >> 9); }
    unsigned next_int(unsigned mod) { x = x ^ (x << 7); x = x ^ (x >> 9); return x % mod; }
    unsigned next_int(unsigned l, unsigned r) { x = x ^ (x << 7); x = x ^ (x >> 9); return x % (r - l + 1) + l; } // inclusive
    double next_double() { return double(next_int()) / UINT_MAX; }
} rnd;

/* 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_int(i);
        std::swap(v[i], v[r]);
    }
}

/* split */
std::vector<std::string> split(std::string str, const std::string& delim) {
    for (char& c : str) if (delim.find(c) != std::string::npos) c = ' ';
    std::istringstream iss(str);
    std::vector<std::string> parsed;
    std::string buf;
    while (iss >> buf) parsed.push_back(buf);
    return parsed;
}

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);
}

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; }



constexpr int T = 3600;
constexpr int R = 4;
constexpr int NSUM = 5400;

struct Judge {

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

    Judge(std::istream& in, std::ostream& out) : in(in), out(out), tick(0) {
        int buf;
        in >> buf >> buf;
    }

    std::vector<int> receive() {
        std::vector<int> ret;
        int N;
        in >> N;
        for (int i = 0; i < N; i++) {
            int skill;
            in >> skill;
            ret.push_back(skill);
        }
        return ret;
    }

    void send(const std::vector<std::pair<int, int>>& merge_ops) {
        out << merge_ops.size();
        for (const auto& [a, b] : merge_ops) {
            out << '\n' << a + 1 << ' ' << b + 1;
        }
        out << std::endl;
    }

};

int main() {
#ifdef _MSC_VER
    std::ifstream ifs(R"(C:\dev\heuristic\tasks\yukicoder5004\tools\input\0001.txt)");
    std::ofstream ofs(R"(C:\dev\heuristic\tasks\yukicoder5004\tools\output\0001.txt)");
    std::istream& in = ifs;
    std::ostream& out = ofs;
#else
    std::istream& in = std::cin;
    std::ostream& out = std::cout;
#endif

    // N 人溜まったら上位 K 人を決定?

    Judge judge(in, out);

    std::vector<std::vector<int>> bin(21);

    int id = 0;

    for (int tick = 0; tick < T; tick++) {
        auto ret = judge.receive();

        std::vector<std::pair<int, int>> pairs;

        for (int s : ret) {
            if (bin[s / 5].size()) {
                pairs.emplace_back(bin[s / 5].back(), id);
            }
            bin[s / 5].push_back(id);
            if (bin[s / 5].size() == 4) bin[s / 5].clear();
            id++;
        }

        judge.send(pairs);
    }

    return 0;
}

0