-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
68 lines (54 loc) · 2.15 KB
/
Copy pathD.cpp
File metadata and controls
68 lines (54 loc) · 2.15 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>
using namespace std;
#ifndef HELLO_PEOPLE
#define cerr if(0) cout
#endif
using ll = long long;
using ld = long double;
#define all(v) (v).begin(), (v).end()
#define X first
#define Y second
// magic
template<class T> struct Nit { T _v, _s; Nit(T v, T s) : _v(v), _s(s) {} operator T &() { return _v; } T operator *() const { return _v; } Nit &operator++() { _v += _s; return *this; } bool operator!=(Nit &a) { return (_s > 0 ? _v < a._v : _v >= a._v); } }; template<class T = int> struct range { T _b, _e, _s; range(T e) : _b(0), _e(e), _s(1) {} range(T b, T e, T s = 1) : _b(b), _e(e), _s(s) {} Nit<T> begin() { return Nit<T>(_b, _s); } Nit<T> end() { return Nit<T>(_e, _s); } }; template<class T = int> struct rrange : range<T> { rrange(T e, T b, T s = 1) : range<T>(e, b, -s) {} rrange(T e) : range<T>(e, 0, -1) {} }; template<int D, class T> struct vec : public vector<vec<D - 1, T>> { template<class... Args> vec(int n = 0, Args... a) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(a...)) {} }; template<class T> struct vec<1, T> : public vector<T> { vec(int n = 0, T const &val = T()) : vector<T>(n, val) {} };
// now start
ll constexpr INF = 1e14;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
auto &&run_case = []() {
int n, k;
cin >> n >> k;
vector<int> r(n);
int d = k / n;
fill(all(r), d);
int rm = k % n;
for (auto i : range<>(rm)) {
r[i]++;
}
vec<2, int> mp(n, n);
int j = 0;
for (auto i : range<>(n)) {
for (auto x : range<>(r[i])) {
j = (j + 1) % n;
mp[i][j] = 1;
}
}
vector<int> c(n);
for (auto x : range<>(n)) {
for (auto i : range<>(n)) {
c[j] += mp[i][x];
}
}
cout << !!rm * 2 << '\n';
for (auto i : range<>(n)) {
for (auto x : range<>(n)) {
cout << mp[i][x];
}
cout << '\n';
}
};
int tc;
cin >> tc;
while (tc--) run_case();
return 0;
}