From bc1489d320d619800b7ace6426e49069821d5038 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Fri, 8 May 2026 15:57:19 +0900 Subject: [PATCH] complete ojuz/KAISTRUN26SPRING_A.cpp --- .../ojuz/cpp/completed/KAISTRUN26SPRING_A.cpp | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 storage/ojuz/cpp/completed/KAISTRUN26SPRING_A.cpp diff --git a/storage/ojuz/cpp/completed/KAISTRUN26SPRING_A.cpp b/storage/ojuz/cpp/completed/KAISTRUN26SPRING_A.cpp new file mode 100644 index 0000000..44c11d7 --- /dev/null +++ b/storage/ojuz/cpp/completed/KAISTRUN26SPRING_A.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include + +#define let auto +#define fn auto +#define usize size_t +using u32 = uint32_t; +using namespace std; + +const u32 KX = 123456789; +const u32 KY = 362436069; +const u32 KZ = 521288629; +const u32 KW = 88675123; + +fn fastio() { + ios::sync_with_stdio(false); + cin.tie(nullptr); +} + +struct Rand { + u32 x, y, z, w; + + static Rand new_seed(u32 seed) { + return {KX ^ seed, KY ^ seed, KZ, KW}; + } + + u32 rand() { + u32 t = x ^ (x << 11); + x = y; + y = z; + z = w; + w ^= (w >> 19) ^ t ^ (t >> 8); + return w; + } + + template + void shuffle(vector& a) { + if (a.empty()) return; + usize i = a.size() - 1; + while (i > 0) { + usize j = rand() % (i + 1); + swap(a[i], a[j]); + i--; + } + } + + u32 rand_range(u32 a, u32 b) { + u32 m = b - a + 1; + return a + rand() % m; + } + + double rand_float() { + return static_cast(rand()) / static_cast((u32)-1); + } +}; + +fn main() -> int { + fastio(); + + istreambuf_iterator it(cin), end; + string temp(it, end); + vector vals; + usize pos = 0; + while (pos < temp.size()) { + while (pos < temp.size() && isspace(temp[pos])) pos++; + if (pos >= temp.size()) break; + usize start = pos; + while (pos < temp.size() && !isspace(temp[pos])) pos++; + vals.push_back(stoul(temp.substr(start, pos - start))); + } + + auto it2 = vals.begin(); + u32 n = *it2++; + u32 m = *it2++; + + vector> requests; + for (u32 i = 0; i < m; i++) { + u32 w = *it2++ - 1; + u32 x = *it2++ - 1; + u32 y = *it2++ - 1; + u32 z = *it2++ - 1; + u32 k = *it2++; + requests.emplace_back(w, x, y, z, k); + } + + u32 trial = 0; + while (true) { + Rand rand = Rand::new_seed(trial); + vector music(n); + for (u32 i = 0; i < n; i++) { + music[i] = rand.rand_range(0, 3); + } + + u32 cnt = 0; + for (const auto& req : requests) { + u32 w, x, y, z, k; + tie(w, x, y, z, k) = req; + if ((music[w] + music[x] + music[y] + music[z]) % 4 == k) { + cnt++; + } + } + if (m / 4 <= cnt) { + for (u32 a : music) { + cout << a << ' '; + } + break; + } + trial++; + } + return 0; +} \ No newline at end of file