Here is the link to the contest.
A. Valid Parentheses
Solution
Code
B. Chef Jamie
Solution
Code
C. Experiment
Solution
Code
D. Minimum Park Lighting Cost
Solution
Code
E. Secure The Castle
Solution
Code
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
A2SV Remote G5 — Contest #25 Editorial
Here is the link to the contest.
The most optimal length is achieved if no parentheses need to be removed, but sometimes parentheses must be removed to maintain the balanced property. This happens when encountering a ) before a matching (. To solve this, traverse the string from left to right. Every time you encounter a (, increment the open parentheses count by one. If you encounter a ), the count of open parentheses must be at least one. If it is, decrement the count by one and increment your result by two (one for the ( and one for the ) because both are part of the remaining valid string). If not, it means you have to remove this closing parenthesis.
def solve():
s = input()
result = opened = 0
for ch in s:
if ch == '(':
opened += 1
elif opened:
result += 2
opened -= 1
print(result)
if __name__ == "__main__":
solve()
To solve this problem we have to use stack
def solve():
To solve this problem we have to use stack
def solve():
To solve this problem we have to use stack
def solve():
To solve this problem we have to use stack
def solve():
Rev. | Lang. | By | When | Δ | Comment | |
---|---|---|---|---|---|---|
en25 | bahailu | 2024-07-27 21:37:08 | 0 | (published) | ||
en24 | bahailu | 2024-07-27 21:26:30 | 88 | |||
en23 | bahailu | 2024-07-27 21:25:34 | 36 | |||
en22 | bahailu | 2024-07-27 21:23:54 | 51 | |||
en21 | bahailu | 2024-07-27 21:20:19 | 991 | Tiny change: 'oiler>\n\n**What' -> 'oiler>\n\n[likes:1]\n\n**What' | ||
en20 | bahailu | 2024-07-27 20:50:56 | 226 | |||
en19 | bahailu | 2024-07-27 20:30:50 | 3 | Tiny change: '``python\n directions' -> '``python\ndirections' | ||
en18 | bahailu | 2024-07-27 20:30:07 | 2864 | |||
en17 | bahailu | 2024-07-27 18:04:52 | 1389 | Tiny change: '\n \n`<spoiler s' -> '\n \n```\n</spoiler>\n\n\n\n<spoiler s' | ||
en16 | bahailu | 2024-07-27 17:52:12 | 1341 | |||
en15 | bahailu | 2024-07-27 17:33:15 | 49 | Tiny change: 'n</spoiler?\n\n[B. Ch' -> 'n</spoiler>\n\n[B. Ch' | ||
en14 | bahailu | 2024-07-27 17:17:01 | 609 | |||
en13 | bahailu | 2024-07-27 17:15:26 | 2139 | |||
en12 | bahailu | 2024-07-27 16:31:41 | 403 | |||
en11 | bahailu | 2024-07-27 16:26:55 | 354 | |||
en10 | bahailu | 2024-07-27 16:19:51 | 258 | |||
en9 | bahailu | 2024-07-27 16:18:02 | 983 | |||
en8 | bahailu | 2024-07-27 15:17:13 | 886 | |||
en7 | bahailu | 2024-07-27 15:01:22 | 147 | |||
en6 | bahailu | 2024-07-27 15:00:05 | 525 | |||
en5 | bahailu | 2024-07-27 14:59:19 | 164 | |||
en4 | bahailu | 2024-07-27 14:55:29 | 666 | |||
en3 | bahailu | 2024-07-27 14:53:24 | 550 | |||
en2 | bahailu | 2024-07-27 14:48:39 | 134 | |||
en1 | bahailu | 2024-07-27 14:45:14 | 250 | Initial revision (saved to drafts) |
Name |
---|