Problem A -- Akash and the Fortnite String
The string "abababab..."
of length $$$k + 1$$$ is a $$$k$$$-Fortnite string. Then, set a variable s = "a"
, and add "a"
or "b"
to s
$$$k$$$ times.
import sys, math, random
input = sys.stdin.readline
out = []
for _ in range(int(input())):
n = int(input())
s = "a"
for i in range(k):
if i % 2 == 0:
s += "b"
else:
s += "a"
out.append(s)
print("\n".join(out))
Problem B -- Akash and the Lactation Pod
First, sort the array of initial positions $$$a$$$.
Note that if there are two business majors on consecutive squares, Akash cannot get past them. Thus, we can loop through $$$a$$$ and check that no two consecutive elements are consecutive.
If there are no business majors blocking the path, Akash can reach the lactation pod in $$$n - 1$$$ seconds.
If the positions of two consecutive business majors have the same parity, Akash can get by both without pausing. Otherwise, if they have the same parity, Akash must pause one second to ensure he can move past the second business major. Additionally, if the first business major is on an odd square, Akash must wait a second to get past the first business major.
We can keep a variable curParity
representing the parity of the last processed business major. Initially, curParity
is set to 0
, representing the fact that if the first business major is on an odd square, Akash must wait a second. Also, keep a counter pauses
to count how many times Akash must pause.
Then, loop through the array $$$a$$$. If the position of the next business major has a different parity than curParity
, then increment pauses
by $$$1$$$ and update curParity
. Otherwise, Akash does not have to pause, and no action needs to be taken.
Then, we can print $$$n - 1$$$ added to the number of pauses.
import sys
input = sys.stdin.readline
out = []
for _ in range(int(input())):
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(m - 1):
if A[i] + 1 == A[i+1]:
out.append(-1)
break
else:
curPar = 0
pauses = 0
for x in A:
if x % 2 != curPar:
curPar = x % 2
pauses += 1
out.append(n - 1 + pauses)
print("\n".join(map(str, out)))