Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B"You are given a n x n chessboard. Rows and columns of the board are numbered from 1 to n . Cell (x, y) lies on the intersection of column number x and row number y . Rook is a chess piece, that can in one turn move any number of cells vertically or horizontally. There are m rooks ( m < n ) placed on the chessboard in such a way that no pair of rooks attack each other. I.e. there are no pair of rooks that share a row or a column. In one turn you can move one of the rooks any number of cells vertically or horizontally. Additionally, it shouldn't be attacked by any other rook after movement. What is the minimum number of moves required to place all the rooks on the main diagonal? The main diagonal of the chessboard is all the cells (i, i) , where 1 <= i <= n . The first line contains the number of test cases t ( 1 <= q t <= q 10^3 ). Description of the t test cases follows. The first line of each test case contains two integers n and m -- size of the chessboard and the number of rooks ( 2 <= q n <= q 10^5 , 1 <= q m < n ). Each of the next m lines contains two integers x_i and y_i -- positions of rooks, i -th rook is placed in the cell (x_i, y_i) ( 1 <= q x_i, y_i <= q n ). It's guaranteed that no two rooks attack each other in the initial placement. The sum of n over all test cases does not exceed 10^5 . For each of t test cases print a single integer -- the minimum number of moves required to place all the rooks on the main diagonal. It can be proved that this is always possible. Possible moves for the first three test cases: "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
101930279 |
_elgir |
C |
Dec. 21, 2020, 4:58 a.m. |
OK |
GNU C++11 |
TESTS |
12 |
46 |
409600 |
|
|
101924763 |
GSHgsh |
C |
Dec. 21, 2020, 2:13 a.m. |
OK |
GNU C++11 |
TESTS |
12 |
46 |
3788800 |
|
|
101928646 |
IndignantHydra |
C |
Dec. 21, 2020, 4:21 a.m. |
OK |
GNU C++11 |
TESTS |
12 |
93 |
2969600 |
|
|
101932372 |
myav |
C |
Dec. 21, 2020, 5:42 a.m. |
OK |
GNU C++11 |
TESTS |
12 |
124 |
6451200 |
|
|
101928893 |
rayton.chen |
C |
Dec. 21, 2020, 4:27 a.m. |
OK |
GNU C++11 |
TESTS |
12 |
124 |
7680000 |
|
|
101926056 |
For_Love |
C |
Dec. 21, 2020, 3:05 a.m. |
OK |
GNU C++11 |
TESTS |
12 |
296 |
819200 |
|
|
101910143 |
hello.zhouhongkuan |
C |
Dec. 20, 2020, 6:26 p.m. |
OK |
GNU C++11 |
TESTS |
11 |
296 |
1638400 |
|
|
101932725 |
lazy_learner |
C |
Dec. 21, 2020, 5:49 a.m. |
OK |
GNU C++11 |
TESTS |
12 |
311 |
819200 |
|
|
101908748 |
hello.zhouhongkuan |
C |
Dec. 20, 2020, 6:12 p.m. |
OK |
GNU C++11 |
TESTS |
11 |
312 |
1638400 |
|
|
101881618 |
inbarking |
C |
Dec. 20, 2020, 3:47 p.m. |
OK |
GNU C++11 |
TESTS |
11 |
327 |
409600 |
|
|
101913915 |
ariloc |
C |
Dec. 20, 2020, 7:24 p.m. |
OK |
GNU C++14 |
TESTS |
12 |
62 |
1638400 |
|
|
101930735 |
n00bie_1004 |
C |
Dec. 21, 2020, 5:08 a.m. |
OK |
GNU C++14 |
TESTS |
12 |
62 |
2355200 |
|
|
101888070 |
rickbaishuak |
C |
Dec. 20, 2020, 4:09 p.m. |
OK |
GNU C++14 |
TESTS |
11 |
77 |
921600 |
|
|
101896400 |
litlemaga |
C |
Dec. 20, 2020, 4:38 p.m. |
OK |
GNU C++14 |
TESTS |
11 |
77 |
1638400 |
|
|
101887801 |
BY_KUTBILIM |
C |
Dec. 20, 2020, 4:08 p.m. |
OK |
GNU C++14 |
TESTS |
11 |
77 |
2764800 |
|
|
101925258 |
shoryak |
C |
Dec. 21, 2020, 2:34 a.m. |
OK |
GNU C++14 |
TESTS |
12 |
77 |
25292800 |
|
|
101902560 |
Boy_of_KutBilim |
C |
Dec. 20, 2020, 4:59 p.m. |
OK |
GNU C++14 |
TESTS |
11 |
93 |
10240000 |
|
|
101891563 |
ItzBeam |
C |
Dec. 20, 2020, 4:21 p.m. |
OK |
GNU C++14 |
TESTS |
11 |
108 |
12492800 |
|
|
101924740 |
felipe.fcw |
C |
Dec. 21, 2020, 2:12 a.m. |
OK |
GNU C++14 |
TESTS |
12 |
124 |
10547200 |
|
|
101880756 |
BratAhmet |
C |
Dec. 20, 2020, 3:44 p.m. |
OK |
GNU C++14 |
TESTS |
11 |
202 |
7884800 |
|
|
101927540 |
vjudge2 |
C |
Dec. 21, 2020, 3:50 a.m. |
OK |
GNU C++17 |
TESTS |
12 |
46 |
8396800 |
|
|
101882841 |
m0t9_ |
C |
Dec. 20, 2020, 3:51 p.m. |
OK |
GNU C++17 |
TESTS |
11 |
61 |
1740800 |
|
|
101899966 |
olegXD |
C |
Dec. 20, 2020, 4:51 p.m. |
OK |
GNU C++17 |
TESTS |
11 |
61 |
5120000 |
|
|
101929536 |
BITree2004 |
C |
Dec. 21, 2020, 4:42 a.m. |
OK |
GNU C++17 |
TESTS |
12 |
61 |
7372800 |
|
|
101915751 |
Shu_Bham02 |
C |
Dec. 20, 2020, 8:04 p.m. |
OK |
GNU C++17 |
TESTS |
12 |
62 |
409600 |
|
|
101933319 |
maki_chan |
C |
Dec. 21, 2020, 5:59 a.m. |
OK |
GNU C++17 |
TESTS |
12 |
62 |
1228800 |
|
|
101925697 |
HokageDattebayo |
C |
Dec. 21, 2020, 2:52 a.m. |
OK |
GNU C++17 |
TESTS |
12 |
62 |
5529600 |
|
|
101925685 |
HokageDattebayo |
C |
Dec. 21, 2020, 2:52 a.m. |
OK |
GNU C++17 |
TESTS |
12 |
62 |
5529600 |
|
|
101915666 |
Alisher |
C |
Dec. 20, 2020, 8:02 p.m. |
OK |
GNU C++17 |
TESTS |
12 |
62 |
5529600 |
|
|
101931038 |
Aris |
C |
Dec. 21, 2020, 5:15 a.m. |
OK |
GNU C++17 |
TESTS |
12 |
62 |
6553600 |
|
|
101908257 |
Prabhakar_987 |
C |
Dec. 20, 2020, 6:08 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
46 |
1228800 |
|
|
101875846 |
Honey_Badger |
C |
Dec. 20, 2020, 3:30 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
46 |
3174400 |
|
|
101907577 |
Dmitry10005 |
C |
Dec. 20, 2020, 6:04 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
46 |
3276800 |
|
|
101870408 |
Pechalka |
C |
Dec. 20, 2020, 3:18 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
62 |
3993600 |
|
|
101901488 |
Sokolovskaya |
C |
Dec. 20, 2020, 4:56 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
78 |
16691200 |
|
|
101895680 |
Snoudin |
C |
Dec. 20, 2020, 4:36 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
108 |
12390400 |
|
|
101899540 |
anakib1 |
C |
Dec. 20, 2020, 4:49 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
109 |
23654400 |
|
|
101881734 |
DDima |
C |
Dec. 20, 2020, 3:48 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
124 |
25395200 |
|
|
101901254 |
nastya_ka |
C |
Dec. 20, 2020, 4:55 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
140 |
5734400 |
|
|
101904369 |
SanyOK_149191 |
C |
Dec. 20, 2020, 5:03 p.m. |
OK |
GNU C++17 (64) |
TESTS |
11 |
156 |
6041600 |
|
|
101932681 |
Sanju_250406 |
C |
Dec. 21, 2020, 5:48 a.m. |
OK |
Java 11 |
TESTS |
12 |
280 |
5324800 |
|
|
101918452 |
MagentaCobra |
C |
Dec. 20, 2020, 9:13 p.m. |
OK |
Java 8 |
TESTS |
12 |
139 |
0 |
|
|
101896332 |
Shokersss |
C |
Dec. 20, 2020, 4:38 p.m. |
OK |
Java 8 |
TESTS |
11 |
265 |
21299200 |
|
|
101932740 |
rondan |
C |
Dec. 21, 2020, 5:49 a.m. |
OK |
MS C++ 2017 |
TESTS |
12 |
171 |
409600 |
|
|
101904568 |
timofeycherlyonok |
C |
Dec. 20, 2020, 5:04 p.m. |
OK |
MS C++ 2017 |
TESTS |
11 |
171 |
409600 |
|
|
101876876 |
serg3000 |
C |
Dec. 20, 2020, 3:32 p.m. |
OK |
MS C++ 2017 |
TESTS |
11 |
233 |
8499200 |
|
|
101914773 |
WitchOfTruth |
C |
Dec. 20, 2020, 7:42 p.m. |
OK |
PyPy 3 |
TESTS |
12 |
327 |
13619200 |
|
|
101881920 |
bulbunyuk |
C |
Dec. 20, 2020, 3:48 p.m. |
OK |
PyPy 3 |
TESTS |
11 |
966 |
10649600 |
|
|
101901191 |
Hacker1337 |
C |
Dec. 20, 2020, 4:55 p.m. |
OK |
PyPy 3 |
TESTS |
11 |
998 |
11161600 |
|
|
101880921 |
timolai.andrievitch |
C |
Dec. 20, 2020, 3:45 p.m. |
OK |
PyPy 3 |
TESTS |
11 |
998 |
31846400 |
|
|
remove filters
Back to search problems