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'Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup! Actually, Polycarp has already came up with the name but some improvement to it will never hurt. So now he wants to swap letters at some positions in it to obtain the better name. It isn 't necessary for letters to be adjacent. In addition, each of the investors has chosen some index in the name and selected a set of letters that can go there. Indices chosen by different investors are pairwise distinct. If some indices aren 't chosen by any investor then any letter can go there. Finally, Polycarp is sure that the smallest lexicographically name is the best. (Like why do you think Google decided to become Alphabet?) More formally, you are given a string consisting of lowercase Latin letters from "a" to "f". You can swap letters at any positions arbitrary number of times (zero swaps is also possible). What is the smallest lexicographically name you can obtain such that the letter at every position is among the allowed letters? If Polycarp can 't produce any valid name then print "Impossible". The first line is the string s ( 1 <= |s| <= 10^5 ) -- the name Polycarp has came up with. The string consists only of lowercase Latin letters from "a" to "f". The second line contains a single integer m ( 0 <= m <= |s| ) -- the number of investors. The i -th of the next m lines contain an integer number pos_i and a non-empty string of allowed characters for pos_i ( 1 <= pos_i <= |s| ). Each string contains pairwise distinct letters from "a" to "f". pos_1, pos_2, ... , pos_m are pairwise distinct. If any position of the string doesn 't appear in the investors demands then any letter can go in this position. If Polycarp can 't produce any valid name then print "Impossible". '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
40995842 |
__ShaW |
G |
July 31, 2018, 3:44 a.m. |
OK |
FPC |
TESTS |
57 |
483 |
1126400 |
|
2500 |
40403591 |
SovietPower |
G |
July 16, 2018, 8:43 a.m. |
OK |
GNU C++ |
TESTS |
57 |
62 |
409600 |
|
2500 |
40733944 |
hzy9819 |
G |
July 25, 2018, 8:54 a.m. |
OK |
GNU C++ |
TESTS |
57 |
62 |
512000 |
|
2500 |
40728977 |
luogu_bot5 |
G |
July 25, 2018, 6:40 a.m. |
OK |
GNU C++ |
TESTS |
57 |
62 |
512000 |
|
2500 |
40412573 |
Worldwide_D |
G |
July 16, 2018, 1:09 p.m. |
OK |
GNU C++ |
TESTS |
57 |
77 |
32358400 |
|
2500 |
40379985 |
616156 |
G |
July 15, 2018, 1:27 p.m. |
OK |
GNU C++ |
TESTS |
57 |
78 |
28467200 |
|
2500 |
40541566 |
luogu_bot1 |
G |
July 19, 2018, 8:55 a.m. |
OK |
GNU C++ |
TESTS |
57 |
78 |
28774400 |
|
2500 |
41246136 |
zhouzhendong |
G |
Aug. 5, 2018, 1:12 p.m. |
OK |
GNU C++ |
TESTS |
57 |
93 |
26214400 |
|
2500 |
41420877 |
luogu_bot5 |
G |
Aug. 10, 2018, 7:06 a.m. |
OK |
GNU C++ |
TESTS |
57 |
93 |
26316800 |
|
2500 |
41420779 |
fks20011206 |
G |
Aug. 10, 2018, 7:04 a.m. |
OK |
GNU C++ |
TESTS |
57 |
93 |
26316800 |
|
2500 |
41246233 |
zhouzhendong |
G |
Aug. 5, 2018, 1:15 p.m. |
OK |
GNU C++ |
TESTS |
57 |
108 |
26214400 |
|
2500 |
67664929 |
rainboy |
G |
Dec. 26, 2019, 5:27 p.m. |
OK |
GNU C11 |
TESTS |
57 |
61 |
512000 |
|
2500 |
44767057 |
test616.cpp |
G |
Oct. 24, 2018, 10:29 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
61 |
512000 |
|
2500 |
54909433 |
comld |
G |
June 1, 2019, 10:23 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
62 |
512000 |
|
2500 |
54833769 |
comld |
G |
May 30, 2019, 10:02 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
62 |
512000 |
|
2500 |
54833652 |
comld |
G |
May 30, 2019, 10 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
62 |
512000 |
|
2500 |
54791194 |
luogu_bot5 |
G |
May 29, 2019, 7:13 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
62 |
512000 |
|
2500 |
54791167 |
207M |
G |
May 29, 2019, 7:12 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
62 |
512000 |
|
2500 |
57738324 |
py_ultron |
G |
July 25, 2019, 10:39 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
62 |
512000 |
|
2500 |
50994367 |
Rayment |
G |
March 8, 2019, 2:20 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
62 |
26112000 |
|
2500 |
51146533 |
ql_wpc |
G |
March 11, 2019, 1:17 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
62 |
28876800 |
|
2500 |
66775901 |
luogu_bot4 |
G |
Dec. 13, 2019, 10:01 a.m. |
OK |
GNU C++11 |
TESTS |
57 |
77 |
409600 |
|
2500 |
40353623 |
ckodser |
G |
July 14, 2018, 6:30 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
77 |
512000 |
|
2500 |
40359235 |
.Ali. |
G |
July 14, 2018, 10:45 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
77 |
614400 |
|
2500 |
40359751 |
.Ali. |
G |
July 14, 2018, 11:23 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
77 |
819200 |
|
2500 |
40349213 |
halyavin |
G |
July 14, 2018, 4:41 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
77 |
819200 |
|
2500 |
40359722 |
.Ali. |
G |
July 14, 2018, 11:20 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
78 |
819200 |
|
2500 |
64523383 |
yyqchemic |
G |
Nov. 8, 2019, 1:01 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
78 |
921600 |
|
2500 |
40894026 |
Zxyelf |
G |
July 28, 2018, 6:12 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
78 |
1024000 |
|
2500 |
40359486 |
.Ali. |
G |
July 14, 2018, 11:02 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
92 |
26419200 |
|
2500 |
40515407 |
ShakuganSky |
G |
July 18, 2018, 1:07 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
93 |
204800 |
|
2500 |
43037209 |
massimodong |
G |
Sept. 18, 2018, 2:05 p.m. |
OK |
GNU C++14 |
TESTS |
57 |
93 |
614400 |
|
2500 |
40539383 |
Trisolaris |
G |
July 19, 2018, 7:49 a.m. |
OK |
GNU C++17 |
TESTS |
57 |
46 |
1740800 |
|
2500 |
40374628 |
q234rty |
G |
July 15, 2018, 10:14 a.m. |
OK |
GNU C++17 |
TESTS |
57 |
61 |
10547200 |
|
2500 |
40539089 |
Trisolaris |
G |
July 19, 2018, 7:41 a.m. |
OK |
GNU C++17 |
TESTS |
57 |
62 |
1740800 |
|
2500 |
68437709 |
jiangly |
G |
Jan. 9, 2020, 9:37 a.m. |
OK |
GNU C++17 |
TESTS |
57 |
78 |
716800 |
|
2500 |
64677981 |
ccsu_cat_love_jiejie |
G |
Nov. 11, 2019, 8:50 a.m. |
OK |
GNU C++17 |
TESTS |
57 |
78 |
26214400 |
|
2500 |
52899025 |
RNS_JKS |
G |
April 17, 2019, 10:20 a.m. |
OK |
GNU C++17 |
TESTS |
57 |
93 |
614400 |
|
2500 |
62237838 |
nitixkrai |
G |
Oct. 9, 2019, 11:52 p.m. |
OK |
GNU C++17 |
TESTS |
57 |
93 |
716800 |
|
2500 |
53288259 |
Kmcode |
G |
April 25, 2019, 2:41 p.m. |
OK |
GNU C++17 |
TESTS |
57 |
93 |
819200 |
|
2500 |
48946721 |
chinmay0906 |
G |
Jan. 25, 2019, 7:33 p.m. |
OK |
GNU C++17 |
TESTS |
57 |
93 |
8601600 |
|
2500 |
64286701 |
EDawn |
G |
Nov. 5, 2019, 5:12 a.m. |
OK |
GNU C++17 |
TESTS |
57 |
93 |
26214400 |
|
2500 |
67664930 |
Dukkha |
G |
Dec. 26, 2019, 5:27 p.m. |
OK |
Java 11 |
TESTS |
57 |
389 |
0 |
|
2500 |
40777586 |
vovacomua |
G |
July 26, 2018, 12:07 p.m. |
OK |
Java 8 |
TESTS |
57 |
249 |
0 |
|
2500 |
40384273 |
kessido |
G |
July 15, 2018, 4:52 p.m. |
OK |
Java 8 |
TESTS |
57 |
249 |
0 |
|
2500 |
40372611 |
insert_cool_handle |
G |
July 15, 2018, 9 a.m. |
OK |
Java 8 |
TESTS |
57 |
280 |
0 |
|
2500 |
40384130 |
kessido |
G |
July 15, 2018, 4:43 p.m. |
OK |
Java 8 |
TESTS |
57 |
296 |
0 |
|
2500 |
59866564 |
7dan |
G |
Sept. 1, 2019, 5:25 p.m. |
OK |
Java 8 |
TESTS |
57 |
514 |
0 |
|
2500 |
40744744 |
Jerehao |
G |
July 25, 2018, 2:04 p.m. |
OK |
Java 8 |
TESTS |
57 |
577 |
41881600 |
|
2500 |
40491029 |
Taran_1407 |
G |
July 17, 2018, 8:38 p.m. |
OK |
Java 8 |
TESTS |
57 |
638 |
39628800 |
|
2500 |
40652370 |
Intrincantation |
G |
July 23, 2018, 12:30 a.m. |
OK |
Java 8 |
TESTS |
57 |
1340 |
0 |
|
2500 |
46009454 |
NgocNguyen |
G |
Nov. 20, 2018, 7:08 p.m. |
OK |
Java 8 |
TESTS |
57 |
1653 |
0 |
|
2500 |
43475432 |
dalt |
G |
Sept. 27, 2018, 2:56 a.m. |
OK |
Java 8 |
TESTS |
57 |
1668 |
0 |
|
2500 |
41082151 |
LIVE5 |
G |
Aug. 1, 2018, 12:33 p.m. |
OK |
MS C++ |
TESTS |
57 |
140 |
26931200 |
|
2500 |
41216202 |
LIVE5 |
G |
Aug. 4, 2018, 1:07 p.m. |
OK |
MS C++ |
TESTS |
57 |
187 |
26214400 |
|
2500 |
58536788 |
Spiritum |
G |
Aug. 10, 2019, 12:15 p.m. |
OK |
MS C++ 2017 |
TESTS |
57 |
249 |
7270400 |
|
2500 |
40411343 |
kobae964 |
G |
July 16, 2018, 12:35 p.m. |
OK |
Rust |
TESTS |
57 |
811 |
105984000 |
|
2500 |
remove filters
Back to search problems