Official Analysis (in Romanian)
Explanation
After running the brute force solution, one can observe that the period of how matrix looks like is the smallest power of two such that it's greater than both and .
Also, we can reduce the problem to finding the xor-sum of the elements in positions such that the number of roads from to in steps is odd, where is the number of transformations done.
This is equal to , where is choose . Also, if is odd, then (this can also be observed by brute-force).
Also, if and are odd, then is odd as well, so we can reduce the problem to SOS DP, where = xorsum of elements which are in positions included by .
For each bit of the period, , if has the bit on position equal to .
For other approaches, you can also check out the user solutions on Infoarena, just make sure to press that popup you receive after you first click on a solution. Take note that the version used is slightly different from the actual version, as this problem was given as an interactive problem and Infoarena couldn't support interactive problems at the time.
Implementation for infoarena version
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;int main() {ifstream f("xortransform.in");int n, m, q;f >> n >> m >> q;vector<int> sos(n * m * 2 + 1);for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!