Submission #1066421

#TimeUsernameProblemLanguageResultExecution timeMemory
1066421myst6Ancient Machine 2 (JOI23_ancient2)C++17
0 / 100
13 ms600 KiB
#include "ancient2.h" #include <bits/stdc++.h> using namespace std; const int MAX_BITS = 1000; const int MAX_J = 45; const int NUM_EQUATIONS = MAX_J * (MAX_J + 1) / 2; vector<bitset<MAX_BITS>> A(NUM_EQUATIONS); bitset<MAX_BITS> S; bitset<NUM_EQUATIONS> b; void gaussian_elimination() { int row = 0; for (int col = 0; col < MAX_BITS; ++col) { // Find pivot row int pivot = -1; for (int i = row; i < NUM_EQUATIONS; ++i) { if (A[i][col]) { pivot = i; break; } } if (pivot == -1) continue; // No pivot found, move to the next column // Swap pivot row with the current row swap(A[row], A[pivot]); // swap(b[row], b[pivot]); int tmp = b[row]; b[row] = b[pivot]; b[pivot] = tmp; // Eliminate below for (int i = row + 1; i < NUM_EQUATIONS; ++i) { if (A[i][col]) { A[i] ^= A[row]; // b[i] ^= b[row]; if (b[row]) b[i] = !b[i]; } } ++row; } // Backward substitution S.reset(); for (int i = row - 1; i >= 0; --i) { if (A[i].any()) { int leading_one = A[i]._Find_first(); S[leading_one] = b[i]; for (int j = leading_one + 1; j < MAX_BITS; ++j) { if (A[i][j]) { // S[leading_one] ^= S[j]; if (S[j]) S[leading_one] = !S[leading_one]; } } } } } // info[m][r] => index === r (mod m) string solve(vector<vector<int>> &info) { // Populate the matrix A and vector b with parity information int equation_index = 0; for (int j = 1; j <= 45; ++j) { for (int i = 0; i < j; ++i) { for (int k = i; k < MAX_BITS; k += j) { A[equation_index][k] = 1; } b[equation_index] = info[j][i] /* Your parity information for p_{i,j} */; equation_index++; } } assert(equation_index == NUM_EQUATIONS); // Perform Gaussian elimination gaussian_elimination(); // Output the reconstructed binary string return S.to_string(); } string Solve(int N) { vector<vector<int>> info(MAX_J + 1); for (int j=1; j<=MAX_J; j++) { for (int i=0; i<j; i++) { int m = 2 * j; vector<int> a(m), b(m); // nodes r=0..j-1 is even parity modulo r // nodes r=j..2j-1 is odd parity modulo r for (int r=0; r<j; r++) { // both transition to next node in chain a[r] = (r + 1) % j; b[r] = (r + 1) % j; a[j + r] = j + ((r + 1) % j); b[j + r] = j + ((r + 1) % j); } // if one, transition to opposite node in chain b[i] = j + ((i + 1) % j); b[i + j] = (i + 1) % j; info[j].push_back(Query(m, a, b)); } } return solve(info); }
#Verdict Execution timeMemoryGrader output
Fetching results...