結果
| 問題 |
No.5004 Room Assignment
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-01 21:02:38 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 146 ms / 5,000 ms |
| コード長 | 10,466 bytes |
| コンパイル時間 | 2,961 ms |
| 実行使用メモリ | 22,356 KB |
| スコア | 137,737,701 |
| 平均クエリ数 | 7642.75 |
| 最終ジャッジ日時 | 2021-12-01 21:03:01 |
| 合計ジャッジ時間 | 21,942 ms |
|
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 100 |
ソースコード
#include <bits/stdc++.h>
#include <random>
#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);
bool x[101] = {
0,0,0,0,0,0,0,0,0,0,
1,0,0,0,0,1,0,0,0,0,
1,0,0,0,0,1,0,0,0,0,
1,0,0,0,0,1,0,0,0,0,
1,0,0,0,1,0,0,0,1,0,
0,0,1,0,0,0,1,0,0,0,
1,0,0,0,0,1,0,0,0,0,
1,0,0,0,0,1,0,0,0,0,
1,0,0,0,0,1,0,0,0,0,
1,0,0,0,0,0,0,0,0,0,
1
};
std::map<int, std::vector<int>> bin;
for (int s = 0; s <= 100; s++) if (x[s]) bin[s] = {};
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) {
int v = bin.lower_bound(s)->first;
if (bin[v].size()) {
pairs.emplace_back(bin[v].back(), id);
}
bin[v].push_back(id);
if (bin[v].size() == 4) bin[v].clear();
id++;
}
judge.send(pairs);
}
return 0;
}