cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

mex_grid_construction_3419.cpp (595B)


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