forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE1.cpp
More file actions
66 lines (62 loc) · 1.23 KB
/
E1.cpp
File metadata and controls
66 lines (62 loc) · 1.23 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
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef double R;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, s, t) for(i = (s); i < (t); i++)
#define RFOR(i, s, t) for(i = (s)-1; i >= (t); i--)
const R PI = acos(-1);
const int N = 1<<20;
const int P = 1e9+7;
int a[1000][1000];
R calc(int n, int m){
R ret = 0;
int i, j;
i = n/2-1;
for(j = 0; j < m; j++)
ret += abs(a[i][j] - a[i+1][j]);
return ret;
}
int main(){
#ifdef LOCAL
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
int N;
scanf("%d", &N);
while(N--){
int n, m;
int i, j, k;
scanf("%d%d", &n, &m);
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
scanf("%d", &a[i][j]);
R a1 = calc(n, m);
for(i = 0; i < n/2; i++)
for(j = 0; j < m; j++)
swap(a[i][j], a[i+n/2][j]);
R a2 = calc(n ,m);
if(a2 < a1)
puts("YES");
else
puts("NO");
}
return 0;
}