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
Step 1: Check for infinite movement caused by *
If the string contains two consecutive asterisks (**), or if an asterisk is next to an arrow in the wrong direction (*< or >*), then Mash can choose directions that let him move left, then right, then left again, and continue indefinitely. In all of these cases, the answer is −1, and we stop immediately.
Step 2: Check for infinite movement without *
Next, we imagine removing all * characters from the string. If the remaining string contains the pattern ><, Mash can move back and forth between those two cells forever. So again, the answer is −1.
Step 3: Find the maximum sailing time
If none of the infinite cases occur, Mash will eventually reach the shore. Now we calculate how long he can sail at most.
We look at each position in the string:
- If the current character is $$$ \lt $$$ Mash will keep moving left until he reaches the shore, passing all cells to the left of that position.
- If the character is $$$ \gt $$$, he will move right until reaching the shore, passing all cells to the right.
- If the character is $$$*$$$, Mash can choose the direction that allows him to pass more cells, so we take the better of moving left or right.
We keep track of the maximum number of cells he can pass from any starting position.
t = int(input())
for _ in range(t):
s = input()
if '**' in s or '*<' in s or '>*' in s:
return print(-1)
net = ''.join([char for char in s if char != '*'])
if '><' in net:
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 s must be a subsequence of t. This means all characters of s should appear in t in the same order. - We use a two-pointer approach to verify this condition.
Frequency Condition: - Let f(str, a) represent the number of occurrences of character a in str. - The condition f(s, a) + f(p, a) ≥ f(t, a) must hold for every character a to ensure thatp provides any missing characters required to build t.
If both conditions are met, we print YES, otherwise, we print 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()



