Codeforces Round #546 (Div. 2) C

在这里插入图片描述
Input
Copy
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
Copy
YES

#include<bits/stdc++.h>
using namespace std;
vector<int> A[1010];
vector<int> B[1010];
int main()
{
  int N, M; scanf("%d%d", &N, &M);
  for(int i=0; i<N; ++i)
    for(int j=0; j<M; ++j)
    {
      int t; scanf("%d", &t);
      A[i+j].push_back(t);
    }
  for(int i=0; i<N; ++i)
    for(int j=0; j<M; ++j)
    {
      int t; scanf("%d", &t);
      B[i+j].push_back(t);
    }
  for(int i=0; i<=N+M-2; ++i)
  {
    sort(A[i].begin(), A[i].end());
    sort(B[i].begin(), B[i].end());
    if(A[i]!=B[i])
    {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
}

猜你喜欢

转载自blog.csdn.net/weixin_43870114/article/details/88697001