-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathc.cc
More file actions
43 lines (38 loc) · 846 Bytes
/
c.cc
File metadata and controls
43 lines (38 loc) · 846 Bytes
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
// https://codeforces.com/contest/1208/problem/C
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
vvi a;
void f(int xo, int yo, int ko, int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
a[yo + i][xo + j] = ko + i * n + j;
}
}
int main() {
int n;
cin >> n;
a = vvi(n, vi(n));
int x = 2;
while (x * 2 <= n) x *= 2;
f(0, 0, 0, x);
int xo = x, ko = x * x;
for (x /= 2; xo < n; x /= 2) {
if (xo + x > n) continue;
for (int i = 0; i < xo; i += x) {
f(xo, i, ko, x);
ko += x * x;
}
for (int i = 0; i < xo; i += x) {
f(i, xo, ko, x);
ko += x * x;
}
f(xo, xo, ko, x);
ko += x * x;
xo += x;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cout << a[i][j] << " \n"[j == n - 1];
}