Submission #1111268

#TimeUsernameProblemLanguageResultExecution timeMemory
1111268thieunguyenhuyMessage (IOI24_message)C++17
100 / 100
2755 ms1112 KiB
#ifndef hwe #include "message.h" #endif #include <bits/stdc++.h> using namespace std; #define popcount(n) (__builtin_popcountll((n))) #define clz(n) (__builtin_clzll((n))) #define ctz(n) (__builtin_ctzll((n))) #define lg(n) (63 - __builtin_clzll((n))) #define BIT(n, i) (((n) >> (i)) & 1ll) #define MASK(i) (1ll << (i)) #define FLIP(n, i) ((n) ^ (1ll << (i))) #define ON(n, i) ((n) | MASK(i)) #define OFF(n, i) ((n) & ~MASK(i)) #define Int __int128 #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long long, int> pli; typedef pair<int, long long> pil; typedef vector<pair<int, int>> vii; typedef vector<pair<long long, long long>> vll; typedef vector<pair<long long, int>> vli; typedef vector<pair<int, long long>> vil; template <class T1, class T2> bool maximize(T1 &x, T2 y) { if (x < y) { x = y; return true; } return false; } template <class T1, class T2> bool minimize(T1 &x, T2 y) { if (x > y) { x = y; return true; } return false; } template <class T> void remove_duplicate(vector<T> &ve) { sort (ve.begin(), ve.end()); ve.resize(unique(ve.begin(), ve.end()) - ve.begin()); } mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); template <class T> T random(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <class T> T random(T r) { return rng() % r; } const int N = 1e6 + 5; const int MOD = 1e9 + 7; const int inf = 1e9; const long long INF = 1e18; #ifdef hwe vector<bool> M, C; vector<vector<bool>> R; vector<bool> send_packet(vector<bool> A) { assert(A.size() == 31); for (int i = 0; i < 31; ++i) if (C[i] == 1) { A[i] = random(2); } R.emplace_back(A); return A; } #endif void send_message(vector<bool> M, vector<bool> C) { vector<int> pos; pos.reserve(16); for (int i = 0; i < 31; ++i) if (!C[i]) { pos.emplace_back(i); } assert(pos.size() == 16); int bitM = 0; auto nextBit = [&]() { if (bitM < M.size()) return bool(M[bitM++]); return !M.back(); }; vector<vector<bool>> packets(66, vector<bool>(31, 0)); for (int i = 0; i < 16; ++i) { int d = (pos[(i + 1) % 16] - pos[i] + 31) % 31; packets[d - 1][pos[i]] = 1; for (int j = d; j < 66; ++j) { packets[j][pos[i]] = nextBit(); } } for (auto packet : packets) send_packet(packet); } vector<bool> receive_message(vector<vector<bool>> R) { vector<int> nxt(31, -1); for (int i = 0; i < 66; ++i) { vector<bool> packet = R[i]; for (int j = 0; j < 31; ++j) if (packet[j] && nxt[j] == -1) { nxt[j] = (j + i + 1) % 31; } } vector<int> pos; pos.reserve(16); for (int i = 0; i < 31; ++i) { vector<bool> vis(31, false); int u = i, cycleSize = 0; while (!vis[u] && nxt[u] != -1) { vis[u] = true, ++cycleSize; u = nxt[u]; } if (cycleSize == 16) { for (int j = 0, u = i; j < 16; ++j, u = nxt[u]) { pos.emplace_back(u); } break; } } sort (pos.begin(), pos.end()); vector<bool> M; for (int i = 0; i < 16; ++i) { int d = (pos[(i + 1) % 16] - pos[i] + 31) % 31; for (int j = d; j < 66; ++j) M.emplace_back(R[j][pos[i]]); } int last = M.back(); while (M.back() == last) M.pop_back(); return M; } #ifdef hwe void solve(bool isLocal = false) { M.assign(1024, 0), C.assign(31, 0), R.clear(); for (int i = 0; i < M.size(); ++i) { M[i] = random(2); } vector<int> index(31); iota(index.begin(), index.end(), 0); shuffle(index.begin(), index.end(), rng); for (int i = 0; i < 15; ++i) C[index[i]] = 1; if (isLocal) { cerr << "M = "; for (auto x : M) cerr << x; cerr << '\n'; cerr << "C = "; for (auto x : C) cerr << x; cerr << '\n'; } send_message(M, C); vector<bool> ans = receive_message(R); if (isLocal) { cerr << "Ans: "; for (auto x : ans) cerr << x; cerr << '\n'; if (ans == M) cerr << "Accepted\n"; else { cerr << "Wrong Answer\n"; exit(0); } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); for (int _ = 0; _ < 10; ++_) { solve(true); } cerr << '\n'; return 0; } #endif

Compilation message (stderr)

message.cpp: In lambda function:
message.cpp:93:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   if (bitM < M.size()) return bool(M[bitM++]);
      |       ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...