forked from apurvapriyadarshi/codeforces-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
625c.cpp
62 lines (61 loc) · 1.25 KB
/
625c.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
//cout << "Hello World!" << endl;
ll n , k;
cin >> n >> k;
ll a[n][n];
ll table[n*n];
for(ll i = 0 ; i < n*n ; i++)
table[i] = 0;
for(ll i = 0 ; i < n ; i++)
{
for(ll j = 0 ; j < n ; j++)
a[i][j] = -1;
}
ll num = n*n; //cout << num;
ll count = 0;
ll sum = 0;
num = num - n + k; //cout << num;
for(ll i = 0 ; i < n ; i++)
{
a[i][k-1] = num;
table[num] = 1;
ll x = num+1;
for(ll j = k ; j < n ; j++)
{
a[i][j] = x;
table[x] = 1;
x++;
}
sum += (num);
//cout << num << " ";
num = num - n + k - 1;
}
num = 1;
cout << sum << endl;
for(ll i = 0 ; i < n ; i++)
{
for(ll j = 0 ; j < n ; j++)
{
if(a[i][j] == -1)
{
a[i][j] = num;
num++;
}
//cout << a[i][j] << " ";
}
//cout << endl;
}
for(ll i = 0 ; i < n ; i++)
{
for(ll j = 0 ; j < n ; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}