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<=个交换法则, ...
随机推荐
- .Net 登陆的时候添加验证码
一.ASPX 登陆界面验证码 1.登陆验证码图片和输入验证码框 <asp:TextBox ID="txtValiCode" runat="server" ...
- c#源码如何生成托管代码块
1.使用编程语言编写源码--->编程语言的编译器(面向Clr)---->生成IL代码和元数据(包含:代码中声名的类和成员 以及所引用的成员) 2.IL就被称之为托管代码,因为有Clr管理者 ...
- 从零开始学安全(十九)●PHP数组函数
$temp= array(1,2,3,,,,) 创建一个数组赋值给temp $id=range(1,6,2); 成长值 1到6 跨度为2 就是3个长度数组 也可以是字符“a” &quo ...
- FastDFS搭建
a.上传安装时需要的文件 ①:FastDFS_v5.05.tar.gz ②:fastdfs-nginx-module_v1.16.tar.gz ③:libfastcommon-1.0.7.tar.gz ...
- Netty实战一之异步和事件驱动
Netty是一款异步的事件驱动的网络应用程序框架,支持快速地开发可维护的高性能的面向协议的服务器和客户端. 使用Netty你可以并不是很需要网络编程.多线程处理.并发等专业Java知识的积蓄. Net ...
- Laravel篇二之本地版本库关联github
以往的工作中都是使用svn作为版本控制,对git分布式的有些陌生,本篇主要记录的本地存储myWeb-laravel的git版本库与github建立关联. 1.首先进入本地myWeb-laravel,执 ...
- Docker多步构建更小的Java镜像
译者按: 最新版Docker将支持多步构建(Multi-stage build),这样使用单个Dockerfile就可以定义多个中间镜像用于构建,测试以及发布等多个步骤,并且有效减小最终镜像的大小. ...
- 封装个 Android 的高斯模糊组件
本篇文章已授权微信公众号 hongyangAndroid (鸿洋)独家发布 最近基于 Android StackBlur 开源库,根据自己碰到的需求场景,封装了个高斯模糊组件,顺便记录一下. 为什么要 ...
- MySQL5.7: datetime
-- 当前日期时间 select now(); select now(3);-- 保留3位毫秒数 SELECT NOW(6); -- 保留6位毫秒数 -- 当前日期和时间 至秒 select curr ...
- 洛谷P4768 [NOI2018]归程(Kruskal重构树)
题意 直接看题目吧,不好描述 Sol 考虑暴力做法 首先预处理出从$1$到每个节点的最短路, 对于每次询问,暴力的从这个点BFS,从能走到的点里面取$min$ 考虑如何优化,这里要用到Kruskal重 ...