Codeforces Round #546 (Div. 2) C. Nastya Is Transposing Matrices
1 second
256 megabytes
standard input
standard output
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices AA and BB are given, each of them has size n×mn×m . Nastya can perform the following operation to matrix AA unlimited number of times:
- take any square square submatrix of AA and transpose it (i.e. the element of the submatrix which was in the ii -th row and jj -th column of the submatrix will be in the jj -th row and ii -th column after transposing, and the transposed submatrix itself will keep its place in the matrix AA ).
Nastya's task is to check whether it is possible to transform the matrix AA to the matrix BB .
Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix MM is a matrix which consist of all elements which comes from one of the rows with indeces x,x+1,…,x+k−1x,x+1,…,x+k−1 of matrix MM and comes from one of the columns with indeces y,y+1,…,y+k−1y,y+1,…,y+k−1 of matrix MM . kk is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
The first line contains two integers nn and mm separated by space (1≤n,m≤5001≤n,m≤500 ) — the numbers of rows and columns in AA and BB respectively.
Each of the next nn lines contains mm integers, the jj -th number in the ii -th of these lines denotes the jj -th element of the ii -th row of the matrix AA (1≤Aij≤1091≤Aij≤109 ).
Each of the next nn lines contains mm integers, the jj -th number in the ii -th of these lines denotes the jj -th element of the ii -th row of the matrix BB (1≤Bij≤1091≤Bij≤109 ).
Print "YES" (without quotes) if it is possible to transform AA to BB and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
2 2
1 1
6 1
1 6
1 1
YES
2 2
4 4
4 5
5 4
4 4
NO
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
YES
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 550;
int a[maxn][maxn];
int b[maxn][maxn];
int ta[maxn*maxn];
int tb[maxn*maxn]; int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
scanf("%d", &a[i][j]);
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
scanf("%d", &b[i][j]);
}
}
for (int i = 1; i <= n + m; i++)
{
int cnta = 0, cntb = 0;
for (int j = 1; j < i; j++)
{
if (j <= n && i - j <= m && i - j >= 1)
{
ta[++cnta] = a[j][i - j];
}
}
for (int j = 1; j < i; j++)
{
if (j <= n && i - j <= m && i - j >= 1)
{
tb[++cntb] = b[j][i - j];
}
}
sort(ta + 1, ta + cnta + 1);
sort(tb + 1, tb + 1 + cntb);
for (int i = 1; i <= cnta; i++)
{
if (ta[i] != tb[i])
{
printf("NO\n");
return 0;
}
}
}
printf("YES\n");
return 0;
}
Codeforces Round #546 (Div. 2) C. Nastya Is Transposing Matrices的更多相关文章
- Codeforces Round #546 (Div. 2) B. Nastya Is Playing Computer Games
链接:https://codeforces.com/contest/1136/problem/B 题意: 有n个井盖,每个井盖上有一个小石头. 给出n和k,k表示刚开始在第k个井盖上方. 有三种操作, ...
- Codeforces Round #546 (Div. 2) A. Nastya Is Reading a Book
链接:https://codeforces.com/contest/1136/problem/A 题意: 给n个区间,每个区间范围不超过100,n不超过100. 给一个位置k,1-(k-1)是遍历过的 ...
- Codeforces Round #546 (Div. 2)-D - Nastya Is Buying Lunch
这道题,神仙贪心题... 题意就是我给出数的顺序,并给出多个交换,每个只能用于相邻交换,问最后一个元素,最多能往前交换多少步. 我们考虑这样一个问题,如果一个这数和a[n]发生交换,那么这个数作为后面 ...
- Codeforces Round #546 (Div. 2) E - Nastya Hasn't Written a Legend
这题是一个贼搞人的线段树 线段树维护的是 区间和a[i - j] 首先对于update的位置可以二分查找 其次update时候的lazy比较技巧 比如更新的是 l-r段,增加的是c 那么这段的值为: ...
- Codeforces Round #546 (Div. 2) 题解
Codeforces Round #546 (Div. 2) 题目链接:https://codeforces.com/contest/1136 A. Nastya Is Reading a Book ...
- Nastya Hasn't Written a Legend(Codeforces Round #546 (Div. 2)E+线段树)
题目链接 传送门 题面 题意 给你一个\(a\)数组和一个\(k\)数组,进行\(q\)次操作,操作分为两种: 将\(a_i\)增加\(x\),此时如果\(a_{i+1}<a_i+k_i\),那 ...
- Codeforces Round #546 (Div. 2)
http://codeforces.com/contest/1136 A #include <bits/stdc++.h> using namespace std; ; int N, K; ...
- Codeforces Round #546 (Div. 2) E 推公式 + 线段树
https://codeforces.com/contest/1136/problem/E 题意 给你一个有n个数字的a数组,一个有n-1个数字的k数组,两种操作: 1.将a[i]+x,假如a[i]+ ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
随机推荐
- C#调用存储过程执行缓慢,但在数据库中执行却很快的问题
参考: http://www.debugease.com/mssqlbasic/976568.html https://www.cnblogs.com/Irving/p/3951220.html ht ...
- springMVC常见错误-解决org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.spring
笔者参考文档: https://blog.csdn.net/sinat_24928447/article/details/47807105 可能错误原因即解决方法: 1.配置文件错误 a)这是配置文件 ...
- SSM-Netty实现软硬件通信,真实项目案例
今天分享的是Myself自己工作项目中的一个模块实例实现的思路还有流程,在这过程中也是遇到了很多问题,能过顺利解决也是团队沟通的结果. 项目模拟背景:假设我们有一个软件平台,我们的线下产品是一些探测器 ...
- Dom对象的研究
1.逻辑运算 || && ! 1||2 5&&4 !0 || 遇到第一个为true 的数字就终止并返回 && 遇到第一个为false ...
- 记录一些日常windows命令或操作技巧
一.远程连接 通常我们发布项目的时候会先发布成本地文件然后通过远程服务器连接放到测试服务器发布成站点,这里就涉及到对远程发布的一些操作. 1. 点击运行,输入 mstsc /admin (这里的adm ...
- angular 分页插件的使用
html: <pagination total-items="totalItems" ng-model="currentPage" items-per-p ...
- JavaScript 基础(三) - Date对象,RegExp对象,Math对象,Window 对象,History 对象,Location 对象,DOM 节点
Date对象 创建Date对象 //方法1:不指定参数 var date_obj = new Date(); alert(date_obj.toLocaleString()) //方法2:参数为日期字 ...
- Python变量和简单数据类型
变量的命名和使用 在Python中使用变量时 ,需要遵守一定的规则和指南. 变量名只能包含字母‘数字和下划线 变量名不能包含空格,但可以用下划线分割其中单词 不要将Python关键字和函数名用作变量名 ...
- Java环境变量搭建
安装JDK开发环境 jdk下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.h ...
- 「Android」adb调试源码(针对dumpsys SurfceFlinger、trace.txt获取)
首先对ADB作简单的阐述,接下来对adb shell dumpsys SurfaceFlinger服务的dump信息的查看.以及ANR问题如何获取trace文件并简单分析. -×*********** ...