blob: feb1171fcf8855771696064dc41bd7efbc492ae7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <algorithm>
#include <bitset>
#include <iostream>
#include <vector>
int firstzero(const std::bitset<200>& b) {
for (int i = 0; i < 200; i++)
if (!b.test(i))
return i;
return -1;
}
int next(int i, int j, std::vector<std::bitset<200>>& col,
std::vector<std::bitset<200>>& row) {
int r = firstzero(row[i] | col[j]);
row[i][r] = col[j][r] = 1;
return r;
}
int main() {
int n;
std::cin >> n;
std::vector<std::bitset<200>> col(n), row(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
std::cout << next(i, j, col, row) << " ";
std::cout << "\n";
}
}
|