/* Enumerate all six-sets meeting at most d old blocks in two or more points. A zero mask denotes a pair omitted from an existing 2-packing. */ typedef unsigned long long U64; typedef struct { U64 word, low, high; } Candidate; static U64 ownerLow[58][58], ownerHigh[58][58], oldBlock[108]; static int numOld, numPoints, limit, stored, capacity; static Candidate *result; static void extend(int first, int size, U64 chosen, U64 low, U64 high) { if (size == 6) { if (__builtin_popcountll(low) + __builtin_popcountll(high) == 1) { int j = low ? __builtin_ctzll(low) : 64 + __builtin_ctzll(high); if (chosen == oldBlock[j]) return; } if (stored < capacity) { result[stored].word = chosen; result[stored].low = low; result[stored].high = high; } ++stored; return; } for (int i = first; i <= numPoints - 6 + size; ++i) { U64 left = chosen, l = low, h = high; while (left) { int j = __builtin_ctzll(left); left &= left - 1; l |= ownerLow[i][j]; h |= ownerHigh[i][j]; } if (__builtin_popcountll(l) + __builtin_popcountll(h) <= limit) extend(i + 1, size + 1, chosen | (1ULL << i), l, h); } } __declspec(dllexport) int enumerate(int n, int m, const U64 *block, int maxConflict, Candidate *out, int maxCount) { if (n > 58 || n < 6 || m > 108 || m < 0) return -1; numPoints = n; numOld = m; limit = maxConflict; result = out; stored = 0; capacity = maxCount; for (int i=0; i