MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Nice Matrix/solution.cpp:23–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21using namespace std;
22
23int main()
24{
25 ios_base::sync_with_stdio(false);
26 cin.tie(NULL);
27 int t ;
28 cin >> t;
29 while (t--)
30 {
31 long long n, m;
32 cin >> n >> m;
33 long long a[n][m];
34 for (int i = 0; i < n; i++)
35 {
36 for (int j = 0; j < m; j++)
37 {
38 cin >> a[i][j];
39 }
40 }
41 if (n == 1 && m == 1)
42 {
43 cout << 0 << endl;
44 }
45 else
46 {
47 int i = 0;
48 long long ans = 0;
49 while (i <= (n - 1) / 2)
50 {
51 int j = 0;
52 while (j <= (m - 1) / 2)
53 {
54 if (i == n - i - 1 && j == m - j - 1)
55 {
56 }
57 else if (i == n - i - 1)
58 {
59 ans += abs(a[i][j] - a[i][m - j - 1]);
60 }
61 else if (j == m - j - 1)
62 {
63 ans += abs(a[i][j] - a[n - i - 1][j]);
64 }
65 else
66 {
67 long long s[4];
68 s[0] = a[i][j];
69 s[1] = a[i][m - j - 1];
70 s[2] = a[n - i - 1][m - j - 1];
71 s[3] = a[n - i - 1][j];
72 sort(s, s + 4);
73 ans += (s[3] + s[2] - s[1] - s[0]);
74 }
75 j++;
76 }
77 i++;
78 }
79 cout << ans << endl;
80 }

Callers

nothing calls this directly

Calls 1

absFunction · 0.85

Tested by

no test coverage detected