当前位置:网站首页>Cf:c. column swapping [sort + simulate]
Cf:c. column swapping [sort + simulate]
2022-07-07 05:56:00 【White speed Dragon King's review】
analysis
Record the position of each row that does not meet the sorting
If there are more than three direct coolings
And then use one set Record what needs to be changed (l,r)
If it is greater than 1 Cool
Then judge each row l r Must satisfy a[l] < a[r]
Otherwise it will be cool
ac code
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, m = list(map(int, input().split()))
grid = [[0] * m for _ in range(n)]
for i in range(n):
grid[i] = list(map(int, input().split()))
flag = True
mustChanges = set()
for i in range(n):
lst = []
temp = sorted(grid[i])
for j in range(m):
if temp[j] != grid[i][j]:
lst.append(j)
if len(lst) > 2:
flag = False
break
elif len(lst) == 2:
mustChanges.add((lst[0], lst[1]))
if len(mustChanges) >= 2:
flag = False
break
if not flag:
print(-1)
else:
if len(mustChanges) == 0:
print(1, 1)
else:
l, r = list(mustChanges)[0]
flag = True
for i in range(n):
if grid[i][l] < grid[i][r]:
flag = False
break
if flag:
print(l + 1, r + 1)
else:
print(-1)
summary
Sort + simulation
边栏推荐
- 上海字节面试问题及薪资福利
- sql查询:将下一行减去上一行,并做相应的计算
- Message queue: how to handle repeated messages?
- 【日常训练--腾讯精选50】235. 二叉搜索树的最近公共祖先
- SAP Spartacus checkout 流程的扩展(extend)实现介绍
- 往图片添加椒盐噪声或高斯噪声
- What are the common message queues?
- Go language context explanation
- 微信小程序蓝牙连接硬件设备并进行通讯,小程序蓝牙因距离异常断开自动重连,js实现crc校验位
- What is dependency injection (DI)
猜你喜欢
The 2022 China low / no code Market Research and model selection evaluation report was released
Question 102: sequence traversal of binary tree
Randomly generate session_ id
如果不知道这4种缓存模式,敢说懂缓存吗?
Realize GDB remote debugging function between different network segments
《2022中国低/无代码市场研究及选型评估报告》发布
What is dependency injection (DI)
Harmonyos practice - Introduction to development, analysis of atomized services
Différenciation et introduction des services groupés, distribués et microservices
Red Hat安装内核头文件
随机推荐
Input of native applet switches between text and password types
驱动开发中platform设备驱动架构详解
PowerPivot——DAX(函数)
Red hat install kernel header file
SAP webservice 测试出现404 Not found Service cannot be reached
老板总问我进展,是不信任我吗?(你觉得呢)
毕业之后才知道的——知网查重原理以及降重举例
[cloud native] what is the microservice architecture?
"Multimodal" concept
Get the way to optimize the one-stop worktable of customer service
Red Hat安装内核头文件
linear regression
Lombok plug-in
Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture
Classic questions about data storage
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略
EMMC打印cqhci: timeout for tag 10提示分析与解决
随机生成session_id
《ClickHouse原理解析与应用实践》读书笔记(6)
三级菜单数据实现,实现嵌套三级菜单数据