import java.io.*; import java.util.*; /** * Read in bitstrings and keep track of only those strings that * increase the rank of the space. This is done by performing * Gaussian Elimination each time a new string is added. * * Get the resulting set of bitstrings in reduced row echelon form * and track the operations used to do this. * Apply those operations to each target bitstring. Perform a binary * search to determine the minimal prefix of bistrings required from * the original set. * Complexity O(nk^3 + m(k^2 + k + log(k))) * * @author Finn Lidbetter */ public class basicbasis_binsearch { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); String[] s = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int m = Integer.parseInt(s[1]); int k = Integer.parseInt(s[2]); BitSet[] arr = new BitSet[k*4]; for (int i=0; i minIndex = new HashMap<>(); int maxColumn = 0; for (int i=0; i0) { BitSet[] copy = makeCopy(arr, maxColumn+1); rref(copy, maxColumn+1, false); if (isConsistent(copy, maxColumn+1)) { if (minSkip==-1) minSkip = i; continue; } minIndex.put(maxColumn, i); maxColumn++; } else { minIndex.put(maxColumn, i); maxColumn++; } } ArrayList ops = rref(arr, maxColumn+1, true); for (int i=0; i 0) ? 1 : 0; } } return arr; } static ArrayList rref(BitSet[] arr, int columns, boolean returnOperations) { int n = arr.length; int m = columns; int r = 0; ArrayList ops = new ArrayList<>(); for (int i = 0; i < m-1 && r ops) { for (Operation op: ops) { if (op.isSwap) { int tmp = arr[op.r1]; arr[op.r1] = arr[op.r2]; arr[op.r2] = tmp; } else { arr[op.r1] ^= arr[op.r2]; } } } } class Operation { int r1; int r2; boolean isSwap; public Operation(int rr1, int rr2, boolean isSwap) { r1 = rr1; r2 = rr2; this.isSwap = isSwap; } }