Codeforces Round 1098 (Div. 2)

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
2228 Codeforces Round 1098 (Div. 2) FINISHED False 8100 1437887 May 16, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 5039 ) C2 Cirno and Number (Hard Version) PROGRAMMING greedy implementation

This is the hard version of the problem. The difference between the versions is that in this version, (1\le n\le 10). You can hack only if you solved all versions of this problem. You are given a non-negative integer (a) and a non-empty, strictly increasing sequence of digits (d) of length (n), where (0 \le d_i \le 9). Find the minimum value of (|a - b|) over all non-negative integers (b) whose decimal representation contains only digits from (d). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains two integers (a) and (n) ((0\le a\le 10^{17}), (1\le n\le 10)). The second line contains (n) integers (d_1,d_2,\ldots,d_n). It is guaranteed that (0\le d_1 \lt d_2 \lt \ldots \lt d_n\le 9). For each test case, output the minimum value of (|a - b|). In the first test case, (a=0), (b=0), and (|a - b|=0). In the second test case, (a=11), (b=11), and (|a - b|=0). In the third test case, (a=222), (b=333), and (|a - b|=111). In the fourth test case, (a=3333), (b=999), and (|a - b|=2334).

Tutorials

Codeforces Round 1098 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
374878058 Tfman C2 May 16, 2026, 10:28 p.m. OK C# 10 TESTS 10 78 6246400
374903988 tmastercubing C2 May 17, 2026, 5:58 a.m. OK C++17 (GCC 7-32) TESTS 10 31 0
374896193 mengmeng123456 C2 May 17, 2026, 4:36 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
374889547 plztuean C2 May 17, 2026, 3:36 a.m. OK C++17 (GCC 7-32) TESTS 10 46 0
374875195 bubbarob19 C2 May 16, 2026, 9:20 p.m. OK C++17 (GCC 7-32) TESTS 10 46 0
374868443 HELICO C2 May 16, 2026, 7:37 p.m. OK C++17 (GCC 7-32) TESTS 10 46 0
374852962 haoran150 C2 May 16, 2026, 4:46 p.m. OK C++17 (GCC 7-32) TESTS 10 46 0
374850488 Mrexcaliver C2 May 16, 2026, 4:42 p.m. OK C++17 (GCC 7-32) TESTS 10 46 0
374846931 devraj_4 C2 May 16, 2026, 4:35 p.m. OK C++17 (GCC 7-32) TESTS 10 46 0
374898225 MinecraftQE C2 May 17, 2026, 5 a.m. OK C++17 (GCC 7-32) TESTS 10 46 102400
374889658 try666 C2 May 17, 2026, 3:37 a.m. OK C++17 (GCC 7-32) TESTS 10 46 102400
374899950 alexey_mitin C2 May 17, 2026, 5:18 a.m. OK C++20 (GCC 13-64) TESTS 10 31 0
374846952 eaeaeaea C2 May 16, 2026, 4:35 p.m. OK C++20 (GCC 13-64) TESTS 10 31 0
374888197 ska_0x08 C2 May 17, 2026, 3:14 a.m. OK C++20 (GCC 13-64) TESTS 10 31 102400
374887327 abac C2 May 17, 2026, 2:59 a.m. OK C++20 (GCC 13-64) TESTS 10 31 4096000
374899157 Yan_1 C2 May 17, 2026, 5:09 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
374896739 silvered C2 May 17, 2026, 4:43 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
374896555 roronova C2 May 17, 2026, 4:41 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
374895771 stars569 C2 May 17, 2026, 4:31 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
374894247 YuukiX C2 May 17, 2026, 4:09 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
374893129 mayy_111 C2 May 17, 2026, 3:53 a.m. OK C++20 (GCC 13-64) TESTS 10 46 0
374852087 David999 C2 May 16, 2026, 4:44 p.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 0
374850141 lokendra_cp C2 May 16, 2026, 4:41 p.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 0
374849177 qazxswwa C2 May 16, 2026, 4:39 p.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 0
374849148 siddnt C2 May 16, 2026, 4:39 p.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 0
374848261 acrems_ C2 May 16, 2026, 4:37 p.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 0
374845982 _1969 C2 May 16, 2026, 4:33 p.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 0
374895691 YF3f3f C2 May 17, 2026, 4:30 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 102400
374895523 YF3f3f C2 May 17, 2026, 4:27 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 102400
374885119 sssine C2 May 17, 2026, 2:15 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 102400
374853607 Akshay1105 C2 May 16, 2026, 4:47 p.m. OK C++23 (GCC 14-64, msys2) TESTS 10 31 102400
374855315 pengin_2000 C2 May 16, 2026, 4:49 p.m. OK GNU C11 TESTS 10 31 0
374854849 1435730 C2 May 16, 2026, 4:49 p.m. OK GNU C11 TESTS 10 31 0
374847706 123fdr C2 May 16, 2026, 4:36 p.m. OK GNU C11 TESTS 10 62 0
374874009 mastacoda C2 May 16, 2026, 8:57 p.m. OK Java 21 TESTS 10 203 307200
374852874 jamshed20 C2 May 16, 2026, 4:46 p.m. OK Java 21 TESTS 10 203 409600
374849869 keshav1405 C2 May 16, 2026, 4:40 p.m. OK Java 21 TESTS 10 234 9011200
374847190 anishchandrapolkampally C2 May 16, 2026, 4:35 p.m. OK Java 21 TESTS 10 250 102400
374869910 SharibSiddiqui C2 May 16, 2026, 7:55 p.m. OK Java 21 TESTS 10 250 716800
374852168 iGNiZ_123 C2 May 16, 2026, 4:44 p.m. OK Java 21 TESTS 10 250 1024000
374846546 GaleStarr C2 May 16, 2026, 4:34 p.m. OK Java 21 TESTS 10 250 18636800
374865323 daniel.glabai C2 May 16, 2026, 7:08 p.m. OK Java 21 TESTS 10 265 716800
374896276 NpHardcore_05 C2 May 17, 2026, 4:37 a.m. OK Java 21 TESTS 10 265 819200
374853652 raghav_guptaa C2 May 16, 2026, 4:47 p.m. OK Java 21 TESTS 10 265 819200
374896527 TheJavaGuy C2 May 17, 2026, 4:41 a.m. OK Java 8 TESTS 10 140 0
374847634 DikshaMitra C2 May 16, 2026, 4:36 p.m. OK Java 8 TESTS 10 171 0
374873755 harsh08 C2 May 16, 2026, 8:52 p.m. OK Java 8 TESTS 10 203 0
374875666 karma_guy C2 May 16, 2026, 9:29 p.m. OK Java 8 TESTS 10 265 0
374870329 gauravkrgupta0954 C2 May 16, 2026, 8 p.m. OK Kotlin 2.2 TESTS 10 281 26009600
374896810 Yuvraj_Rathod C2 May 17, 2026, 4:44 a.m. OK PyPy 3 TESTS 10 437 9932800
374901234 eigen_loop C2 May 17, 2026, 5:32 a.m. OK PyPy 3 TESTS 10 500 9932800
374846528 amega09122190 C2 May 16, 2026, 4:34 p.m. OK PyPy 3-64 TESTS 10 187 7372800
374877126 scooley C2 May 16, 2026, 10:03 p.m. OK PyPy 3-64 TESTS 10 187 9523200
374874221 ANISH_not_so_GREAT C2 May 16, 2026, 9 p.m. OK PyPy 3-64 TESTS 10 250 8806400
374854728 Sneaky_Attack C2 May 16, 2026, 4:49 p.m. OK PyPy 3-64 TESTS 10 265 10649600
374876358 ep268gza C2 May 16, 2026, 9:44 p.m. OK PyPy 3-64 TESTS 10 296 9011200
374846570 didwnghks418 C2 May 16, 2026, 4:34 p.m. OK PyPy 3-64 TESTS 10 296 138649600
374848459 wiem97 C2 May 16, 2026, 4:38 p.m. OK PyPy 3-64 TESTS 10 312 8704000
374850254 Praneet240107 C2 May 16, 2026, 4:41 p.m. OK PyPy 3-64 TESTS 10 328 8806400
374873245 54skyxenon C2 May 16, 2026, 8:44 p.m. OK PyPy 3-64 TESTS 10 328 9523200
374868862 Meitnera1n C2 May 16, 2026, 7:42 p.m. OK PyPy 3-64 TESTS 10 343 9216000
374849001 abheedwivedi C2 May 16, 2026, 4:39 p.m. OK Python 2 TESTS 10 234 0
374854135 Muqeem C2 May 16, 2026, 4:48 p.m. OK Python 3 TESTS 10 171 3276800
374849147 Saadeteen C2 May 16, 2026, 4:39 p.m. OK Python 3 TESTS 10 187 307200
374854312 Goshaloveu C2 May 16, 2026, 4:48 p.m. OK Python 3 TESTS 10 187 512000
374850666 ValeryKulishov C2 May 16, 2026, 4:42 p.m. OK Python 3 TESTS 10 187 1638400
374855201 AeroSol_can C2 May 16, 2026, 4:49 p.m. OK Python 3 TESTS 10 218 307200
374894635 KatsuXD C2 May 17, 2026, 4:15 a.m. OK Python 3 TESTS 10 218 512000
374853196 spy-in-shadows C2 May 16, 2026, 4:46 p.m. OK Python 3 TESTS 10 234 1433600
374868730 amod_24 C2 May 16, 2026, 7:41 p.m. OK Python 3 TESTS 10 250 512000
374886374 Nithin-2001 C2 May 17, 2026, 2:40 a.m. OK Python 3 TESTS 10 265 614400
374846919 WIND2070YT C2 May 16, 2026, 4:35 p.m. OK Python 3 TESTS 10 906 3072000

remove filters

Back to search problems