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
Consider the following game. Two players have a binary string (a string consisting of characters 0 and/or 1 ). The players take turns, the first player makes the first turn. During a player's turn, he or she has to choose exactly two adjacent elements of the string and remove them ( the first element and the last element are also considered adjacent ). Furthermore, there are additional constraints depending on who makes the move: if it's the first player's move, both chosen characters should be 0 ; if it's the second player's move, at least one of the chosen characters should be 1 . The player who can't make a valid move loses the game. This also means that if the string currently has less than (2) characters, the current player loses the game. You are given a binary string (s) of length (n). You have to calculate the number of its substrings such that, if the game is played on that substring and both players make optimal decisions, the first player wins. In other words, calculate the number of pairs ((l, r)) such that (1 \le l \le r \le n) and the first player has a winning strategy on the string (s_l s_{l+1} \dots s_r). The first line contains one integer (n) ((1 \le n \le 3 \cdot 10^5)). The second line contains the string (s), consisting of exactly (n) characters. Each character of the string is either 0 or 1 . Print one integer — the number of substrings such that, if the game is played on that substring, the first player wins. In the first example, the following substrings are winning for the first player ((sl:r) denotes (s_l s_{l+1} \dots s_r)): (s1:2); (s1:3); (s1:7); (s2:4); (s2:8); (s3:5); (s4:5); (s4:6); (s5:7); (s6:8); (s7:8); (s7:9). |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
308246189 |
alwaysCE |
E |
Feb. 28, 2025, 8:40 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
61 |
3379200 |
|
|
|
308291129 |
lsroi |
E |
Feb. 28, 2025, 2:24 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
61 |
9625600 |
|
|
|
308205579 |
Chandra___07 |
E |
Feb. 27, 2025, 9:59 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
62 |
2150400 |
|
|
|
308183383 |
gevak |
E |
Feb. 27, 2025, 5:47 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
62 |
4915200 |
|
|
|
308245335 |
meltdown |
E |
Feb. 28, 2025, 8:33 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
62 |
6041600 |
|
|
|
308226166 |
_XU_ |
E |
Feb. 28, 2025, 5:07 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
62 |
9113600 |
|
|
|
308217680 |
Aurorawlm |
E |
Feb. 28, 2025, 2:52 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
62 |
9318400 |
|
|
|
308251171 |
under_dragon |
E |
Feb. 28, 2025, 9:19 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
62 |
25600000 |
|
|
|
308203854 |
abeker |
E |
Feb. 27, 2025, 9:29 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
77 |
5222400 |
|
|
|
308245914 |
meltdown |
E |
Feb. 28, 2025, 8:38 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
36 |
77 |
6041600 |
|
|
|
308218953 |
ZhiAiCangXing |
E |
Feb. 28, 2025, 3:15 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
46 |
3379200 |
|
|
|
308314996 |
tushaar9876 |
E |
Feb. 28, 2025, 2:54 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
61 |
3379200 |
|
|
|
308266757 |
rdcamelot |
E |
Feb. 28, 2025, 11:28 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
61 |
3379200 |
|
|
|
308241672 |
Rua_vip |
E |
Feb. 28, 2025, 8:02 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
61 |
7270400 |
|
|
|
308251297 |
Laceprndpm |
E |
Feb. 28, 2025, 9:20 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
61 |
8294400 |
|
|
|
308257304 |
FatKid |
E |
Feb. 28, 2025, 10:10 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
62 |
2150400 |
|
|
|
308256330 |
HUAXINWU |
E |
Feb. 28, 2025, 10:02 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
62 |
5120000 |
|
|
|
308270198 |
gMr |
E |
Feb. 28, 2025, 11:53 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
62 |
6348800 |
|
|
|
308271079 |
iordache_ |
E |
Feb. 28, 2025, 11:59 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
62 |
9420800 |
|
|
|
308218533 |
ZhiAiCangXing |
E |
Feb. 28, 2025, 3:08 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
36 |
62 |
9420800 |
|
|
|
308266719 |
jai_hanumant |
E |
Feb. 28, 2025, 11:28 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
46 |
9523200 |
|
|
|
308252038 |
TLE_Automat |
E |
Feb. 28, 2025, 9:26 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
61 |
7065600 |
|
|
|
308223628 |
molongdadi |
E |
Feb. 28, 2025, 4:33 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
61 |
13107200 |
|
|
|
308250233 |
wakaka |
E |
Feb. 28, 2025, 9:12 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
62 |
2252800 |
|
|
|
308225389 |
Calculatelove |
E |
Feb. 28, 2025, 4:57 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
62 |
2252800 |
|
|
|
308263505 |
crocell001 |
E |
Feb. 28, 2025, 11:04 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
62 |
2355200 |
|
|
|
308183330 |
Farhod |
E |
Feb. 27, 2025, 5:47 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
62 |
2457600 |
|
|
|
308279077 |
_Seele_Vollerei_ |
E |
Feb. 28, 2025, 1 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
62 |
3276800 |
|
|
|
308189320 |
postpone |
E |
Feb. 27, 2025, 6:36 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
62 |
3584000 |
|
|
|
308225374 |
ILoveGulim |
E |
Feb. 28, 2025, 4:57 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
36 |
62 |
4608000 |
|
|
|
308215507 |
Acpexia |
E |
Feb. 28, 2025, 2:08 a.m. |
OK |
GNU C11 |
TESTS |
36 |
46 |
5529600 |
|
|
|
308213083 |
srujan___Bunny |
E |
Feb. 28, 2025, 1:11 a.m. |
OK |
Java 21 |
TESTS |
36 |
578 |
65331200 |
|
|
|
308254400 |
ayushdreams147 |
E |
Feb. 28, 2025, 9:46 a.m. |
OK |
PyPy 3 |
TESTS |
36 |
1765 |
228249600 |
|
|
|
308198945 |
ayushdreams147 |
E |
Feb. 27, 2025, 8:18 p.m. |
OK |
PyPy 3 |
TESTS |
36 |
1890 |
228352000 |
|
|
|
308179372 |
BakhtiyarZBJ |
E |
Feb. 27, 2025, 5:19 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
218 |
17920000 |
|
|
|
308237157 |
Musab1Blaser |
E |
Feb. 28, 2025, 7:21 a.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
234 |
42291200 |
|
|
|
308399596 |
IMADOXER |
E |
Feb. 28, 2025, 6:58 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
249 |
42086400 |
|
|
|
308367704 |
mosaab_elouaryarhli2011 |
E |
Feb. 28, 2025, 4:08 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
249 |
42086400 |
|
|
|
308435654 |
young_skywalker_ |
E |
March 1, 2025, 3:26 a.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
281 |
50995200 |
|
|
|
308199171 |
detteiuu |
E |
Feb. 27, 2025, 8:21 p.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
296 |
22835200 |
|
|
|
308433239 |
RauPro |
E |
March 1, 2025, 2:56 a.m. |
OK |
PyPy 3-64 |
TESTS |
36 |
311 |
184422400 |
|
|
|
308180768 |
Dpkasd_12 |
E |
Feb. 27, 2025, 5:28 p.m. |
OK |
Rust 2021 |
TESTS |
36 |
78 |
26521600 |
|
|
remove filters
Back to search problems