Here is the contest link.
A. New Year String
The key observation for solving this problem is that any occurrence of 2025 can be converted into 2026 using a single operation. Therefore, if the given string does not already satisfy any of the conditions stated in the problem, only one operation is needed to create an occurrence of 2026 (since the string contains 2025 when it is not already a New Year string).
As a result, the answer is always either 0 or 1. To determine whether the answer is 0, simply check if the string satisfies at least one of the required conditions. This can be done using the in operator method in Python.
t = int(input())
for _ in range(t):
n = int(input())
s = input()
if '2025' not in s or '2026' in s:
print(0)
else:
print(1)
B. Kidus's Scrambled Notebook
We can iterate over all possible ways to split ab into a and b. For each split, first check whether b has a leading zero. If it does not, compare the integer values of a and b.
To convert a string into an integer, you can use int(s) in Python.
t = int(input())
for _ in range(t):
ab = input()
for i in range(1, len(ab)):
if ab[i] != '0' and int(ab[:i]) < int(ab[i:]):
print(ab[:i], ab[i:])
break
else:
print(-1)
C. Ludis’s Ranker
For each element in the array, we iterate over the entire array and count how many elements are strictly greater than the current one. After computing this count, we add one and include the result in the total sum.
To achieve this, we use two nested loops: the outer loop selects the current element, and the inner loop compares it with every other element in the array. By repeating this process for all elements, we obtain the final answer.
n = int(input())
arr = [int(i) for i in input().split()]
position = []
for i in range(n):
count = 0
for j in range(n):
if arr[i] < arr[j]:
count += 1
position.append(count + 1)
print(*position)
D. Mash and the Awash River
- Check for infinite movement:
- If the string contains two consecutive asterisks
**, - If an asterisk is next to an arrow in the “wrong” direction (
*<or>*), - If there is a
><pattern (an arrow pointing right immediately followed by an arrow pointing left),
-1. - If the string contains two consecutive asterisks
- Calculate the maximum sailing distance if movement is finite:
- For a
<at positioni, Mash can move left to the start, passingi + 1cells. - For a
>at positioni, Mash can move right to the end, passinglen(s) — icells. - For a
*at positioni, Mash can choose the direction that allows him to pass more cells. We take the maximum ofi + 1andlen(s) — i.
- For a
t = int(input())
for _ in range(t):
s = input()
if '**' in s or '*<' in s or '>*' in s or '><' in s:
print(-1)
else:
max_ = 0
for i in range(len(s)):
if s[i] == '<':
max_ = max(max_, i + 1)
elif s[i] == '>':
max_ = max(max_, len(s) - i)
else:
max_ = max(max_, i + 1, len(s) - i)
print(max_)
E. From S To T
To determine if we can form the string t using characters from s and p, we need to check two key conditions:
- Subsequence Condition: The string
smust be a subsequence oft. This means all characters ofsshould appear intin the same order. We can verify this using a two-pointer approach, scanning through both strings simultaneously. - Frequency Condition: Let
f(str, a)represent the number of occurrences of characterainstr. For each charactera, the conditionf(s, a) + f(p, a) ≥ f(t, a)must hold. This ensures that any characters missing fromscan be supplied bypto formt.
If both conditions are satisfied, the answer is YES; otherwise, it is NO.
def solve():
# Read the input strings s, t, and p for the current query
s = input()
t = input()
p = input()
# Check if s is a subsequence of t
i, j = 0, 0
while i < len(s) and j < len(t):
# If characters match, move to the next character in s
if s[i] == t[j]:
i += 1
# Always move to the next character in t
j += 1
# If we couldn't match all characters of s in t, then s is not a subsequence of t
if i != len(s):
print("NO")
return
# Count the frequency of each character in t
freq_t = {}
for char in t:
freq_t[char] = freq_t.get(char, 0) + 1
# Count the frequency of each character in both s and p combined
freq_s_p = {}
for char in s + p:
freq_s_p[char] = freq_s_p.get(char, 0) + 1
# Ensure that for every character in t, we have enough occurrences in s and p
for char, required_count in freq_t.items():
available_count = freq_s_p.get(char, 0)
if required_count > available_count:
print("NO")
return
# If all checks pass, s can be transformed into t using characters from p
print("YES")
# Read the number of queries and process each one
q = int(input())
for _ in range(q):
solve()



