#include #include #ifdef _MSC_VER #include #include #include #include #else #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif /** compro_io **/ /* tuple */ // out namespace aux { template struct tp { static void output(std::ostream& os, const T& v) { os << std::get(v) << ", "; tp::output(os, v); } }; template struct tp { static void output(std::ostream& os, const T& v) { os << std::get(v); } }; } template std::ostream& operator<<(std::ostream& os, const std::tuple& t) { os << '['; aux::tp, 0, sizeof...(Ts) - 1>::output(os, t); return os << ']'; } /* pair */ // out template std::ostream& operator<<(std::ostream& os, const std::pair& p) { return os << "[" << p.first << ", " << p.second << "]"; } // in template std::istream& operator>>(std::istream& is, const std::pair& p) { return is >> p.first >> p.second; } /* container */ // out template std::basic_ostream& operator<<(std::basic_ostream& 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())), class = typename std::enable_if::value>::type > std::istream& operator>>(std::istream& is, T& a) { for (auto& x : a) is >> x; return is; } /* struct */ template 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 std::string format(const std::string& f, Ts... t) { size_t l = std::snprintf(nullptr, 0, f.c_str(), t...); std::vector b(l + 1); std::snprintf(&b[0], l + 1, f.c_str(), t...); return std::string(&b[0], &b[0] + l); } template 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(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 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__<<"]"< 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 void shuffle_vector(std::vector& 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 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 parsed; std::string buf; while (iss >> buf) parsed.push_back(buf); return parsed; } template inline void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template 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 receive() { std::vector 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>& 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> 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> 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; }