当前位置:网站首页>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
边栏推荐
- Go language context explanation
- 上海字节面试问题及薪资福利
- Type de texte de commutation d'entrée et de mot de passe de l'applet natif
- MySQL-CentOS7通过YUM安装MySQL
- 980. 不同路径 III DFS
- STM32 key state machine 2 - state simplification and long press function addition
- Add salt and pepper noise or Gaussian noise to the picture
- yarn入门(一篇就够了)
- Red Hat安装内核头文件
- Web architecture design process
猜你喜欢

I didn't know it until I graduated -- the principle of HowNet duplication check and examples of weight reduction

如果不知道这4种缓存模式,敢说懂缓存吗?

产业金融3.0:“疏通血管”的金融科技

Introduction to distributed transactions

Hcip seventh operation

绕过open_basedir

PowerPivot - DAX (function)

PTA 天梯赛练习题集 L2-004 搜索树判断
Interview questions and salary and welfare of Shanghai byte

Pytorch builds neural network to predict temperature
随机推荐
Mysql-centos7 install MySQL through yum
Digital IC interview summary (interview experience sharing of large manufacturers)
Add salt and pepper noise or Gaussian noise to the picture
【SQL实战】一条SQL统计全国各地疫情分布情况
Go 语言的 Context 详解
980. Different path III DFS
bat 批示处理详解
Web Authentication API兼容版本信息
Bbox regression loss function in target detection -l2, smooth L1, IOU, giou, Diou, ciou, focal eiou, alpha IOU, Siou
关于服装ERP,你知道多少?
Go 語言的 Context 詳解
STM32按键状态机2——状态简化与增加长按功能
软件测试面试技巧
搞懂fastjson 对泛型的反序列化原理
[云原生]微服务架构是什么?
如何提高网站权重
[solved] record an error in easyexcel [when reading the XLS file, no error will be reported when reading the whole table, and an error will be reported when reading the specified sheet name]
什么是消息队列?
C#可空类型
SQL query: subtract the previous row from the next row and make corresponding calculations