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.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
|---|---|---|---|---|---|---|
| 715 | Codeforces Round 372 (Div. 1) | FINISHED | False | 7200 | 302285723 | Sept. 17, 2016, 1:45 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 451 ) | E | Complete the Permutations | PROGRAMMING | combinatorics fft graphs math | 3400 |
ZS the Coder is given two permutations p and q of {1, 2, ..., n } , but some of their elements are replaced with 0 . The distance between two permutations p and q is defined as the minimum number of moves required to turn p into q . A move consists of swapping exactly 2 elements of p . ZS the Coder wants to determine the number of ways to replace the zeros with positive integers from the set {1, 2, ..., n } such that p and q are permutations of {1, 2, ..., n } and the distance between p and q is exactly k . ZS the Coder wants to find the answer for all 0 ≤ k ≤ n - 1 . Can you help him? The first line of the input contains a single integer n ( 1 ≤ n ≤ 250 ) — the number of elements in the permutations. The second line contains n integers, p 1 , p 2 , ..., p n ( 0 ≤ p i ≤ n ) — the permutation p . It is guaranteed that there is at least one way to replace zeros such that p is a permutation of {1, 2, ..., n } . The third line contains n integers, q 1 , q 2 , ..., q n ( 0 ≤ q i ≤ n ) — the permutation q . It is guaranteed that there is at least one way to replace zeros such that q is a permutation of {1, 2, ..., n } . Print n integers, i -th of them should denote the answer for k = i - 1 . Since the answer may be quite large, and ZS the Coder loves weird primes, print them modulo 998244353 = 2 23 ·7·17 + 1 , which is a prime. In the first sample case, there is the only way to replace zeros so that it takes 0 swaps to convert p into q , namely p = (1, 2, 3), q = (1, 2, 3) . There are two ways to replace zeros so that it takes 1 swap to turn p into q . One of these ways is p = (1, 2, 3), q = (3, 2, 1) , then swapping 1 and 3 from p transform it into q . The other way is p = (1, 3, 2), q = (1, 2, 3) . Swapping 2 and 3 works in this case. Finally, there is one way to replace zeros so that it takes 2 swaps to turn p into q , namely p = (1, 3, 2), q = (3, 2, 1) . Then, we can transform p into q like following: . |
| Codeforces Round #372 Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 22173735 | Dylans | E | Nov. 12, 2016, 7:32 a.m. | OK | GNU C++ | TESTS | 136 | 15 | 307200 | 3400 | |
| 20756117 | WuHongxun | E | Sept. 19, 2016, 1:14 p.m. | OK | GNU C++ | TESTS | 136 | 15 | 1331200 | 3400 | |
| 34222968 | wdyhy | E | Jan. 16, 2018, 1:26 p.m. | OK | GNU C++ | TESTS | 136 | 15 | 3481600 | 3400 | |
| 22193217 | XuYipei | E | Nov. 13, 2016, 12:58 p.m. | OK | GNU C++ | TESTS | 136 | 15 | 4096000 | 3400 | |
| 34226041 | wdyhy | E | Jan. 16, 2018, 3:40 p.m. | OK | GNU C++ | TESTS | 136 | 15 | 10240000 | 3400 | |
| 22173078 | hzq84621 | E | Nov. 12, 2016, 6:23 a.m. | OK | GNU C++ | TESTS | 136 | 15 | 15974400 | 3400 | |
| 22186101 | Jin_Haonan | E | Nov. 13, 2016, 2:10 a.m. | OK | GNU C++ | TESTS | 136 | 15 | 16076800 | 3400 | |
| 26457499 | jiyutian | E | April 17, 2017, 2:37 p.m. | OK | GNU C++ | TESTS | 136 | 15 | 18329600 | 3400 | |
| 27815576 | rqgao2014 | E | June 16, 2017, 2:56 a.m. | OK | GNU C++ | TESTS | 136 | 31 | 512000 | 3400 | |
| 20754098 | WuHongxun | E | Sept. 19, 2016, noon | OK | GNU C++ | TESTS | 136 | 31 | 1331200 | 3400 | |
| 22215695 | Remilia-Scarlet | E | Nov. 15, 2016, 1:44 a.m. | OK | GNU C++11 | TESTS | 136 | 15 | 307200 | 3400 | |
| 21998712 | krijgertje | E | Nov. 2, 2016, 5:50 p.m. | OK | GNU C++11 | TESTS | 136 | 15 | 512000 | 3400 | |
| 21422952 | Los_Angelos_Laycurse | E | Oct. 14, 2016, 12:59 p.m. | OK | GNU C++11 | TESTS | 136 | 15 | 2355200 | 3400 | |
| 36071680 | samjia2000 | E | March 8, 2018, 1:04 p.m. | OK | GNU C++11 | TESTS | 136 | 15 | 2560000 | 3400 | |
| 36133974 | gjghfd | E | March 10, 2018, 2:03 a.m. | OK | GNU C++11 | TESTS | 136 | 15 | 5222400 | 3400 | |
| 22173951 | rxdoi | E | Nov. 12, 2016, 7:51 a.m. | OK | GNU C++11 | TESTS | 136 | 15 | 16384000 | 3400 | |
| 22643279 | idy002 | E | Dec. 1, 2016, 3:36 p.m. | OK | GNU C++11 | TESTS | 136 | 30 | 0 | 3400 | |
| 20795293 | anta | E | Sept. 21, 2016, 1:15 p.m. | OK | GNU C++11 | TESTS | 136 | 30 | 409600 | 3400 | |
| 20790961 | ChiliuDog | E | Sept. 21, 2016, 9:12 a.m. | OK | GNU C++11 | TESTS | 136 | 30 | 2048000 | 3400 | |
| 21770936 | jinzhihan | E | Oct. 25, 2016, 12:37 p.m. | OK | GNU C++11 | TESTS | 136 | 30 | 5017600 | 3400 | |
| 22013158 | AmZ | E | Nov. 3, 2016, 1:17 p.m. | OK | GNU C++14 | TESTS | 136 | 15 | 0 | 3400 | |
| 25467957 | King_George | E | March 14, 2017, 7:48 a.m. | OK | GNU C++14 | TESTS | 136 | 15 | 2457600 | 3400 | |
| 36090107 | Merln | E | March 9, 2018, 7:25 a.m. | OK | GNU C++14 | TESTS | 136 | 15 | 5836800 | 3400 | |
| 22188972 | I_Love_Rem | E | Nov. 13, 2016, 8:03 a.m. | OK | GNU C++14 | TESTS | 136 | 15 | 16384000 | 3400 | |
| 21279105 | la1la1la | E | Oct. 8, 2016, 11:45 a.m. | OK | GNU C++14 | TESTS | 136 | 30 | 2662400 | 3400 | |
| 49684026 | black_horse2014 | E | Feb. 10, 2019, 5:42 a.m. | OK | GNU C++14 | TESTS | 136 | 31 | 0 | 3400 | |
| 54912887 | iqqsoszs | E | June 1, 2019, 12:06 p.m. | OK | GNU C++14 | TESTS | 136 | 31 | 512000 | 3400 | |
| 47843267 | The_Unbeatable | E | Jan. 2, 2019, 1:20 p.m. | OK | GNU C++14 | TESTS | 136 | 31 | 1433600 | 3400 | |
| 24113015 | abc473848880 | E | Jan. 25, 2017, 1:56 p.m. | OK | GNU C++14 | TESTS | 136 | 31 | 2252800 | 3400 | |
| 66999364 | dsl2002 | E | Dec. 16, 2019, 4:40 a.m. | OK | GNU C++14 | TESTS | 136 | 31 | 3072000 | 3400 | |
| 64185022 | Gudi_99 | E | Nov. 4, 2019, 4:22 a.m. | OK | GNU C++17 | TESTS | 136 | 31 | 0 | 3400 | |
| 56996905 | Benq | E | July 13, 2019, 11:35 p.m. | OK | GNU C++17 | TESTS | 136 | 31 | 716800 | 3400 | |
| 45801560 | AwD | E | Nov. 16, 2018, 1:35 p.m. | OK | GNU C++17 | TESTS | 136 | 31 | 1331200 | 3400 | |
| 66621410 | EZOJ | E | Dec. 11, 2019, 7:07 a.m. | OK | GNU C++17 | TESTS | 136 | 31 | 4198400 | 3400 | |
| 63238794 | gongsuidashen | E | Oct. 23, 2019, 12:56 p.m. | OK | GNU C++17 | TESTS | 136 | 31 | 64614400 | 3400 | |
| 50260114 | xgcxgc | E | Feb. 20, 2019, 11:20 p.m. | OK | GNU C++17 | TESTS | 136 | 31 | 96358400 | 3400 | |
| 51938621 | Trisolaris | E | March 28, 2019, 1:33 p.m. | OK | GNU C++17 | TESTS | 136 | 46 | 716800 | 3400 | |
| 66504908 | vjudge5 | E | Dec. 8, 2019, 1:59 p.m. | OK | GNU C++17 | TESTS | 136 | 46 | 3072000 | 3400 | |
| 58486049 | includehdhd | E | Aug. 9, 2019, 7:43 a.m. | OK | GNU C++17 | TESTS | 136 | 62 | 33792000 | 3400 | |
| 59070676 | Rose_max | E | Aug. 19, 2019, 4:33 a.m. | OK | GNU C++17 | TESTS | 136 | 62 | 48435200 | 3400 | |
| 20799987 | sweiss | E | Sept. 21, 2016, 3:51 p.m. | OK | Java 8 | TESTS | 136 | 389 | 0 | 3400 | |
| 21422904 | Los_Angelos_Laycurse | E | Oct. 14, 2016, 12:57 p.m. | OK | MS C++ | TESTS | 136 | 30 | 2355200 | 3400 |
Back to search problems