SAZEDUR

Who am I? I don’t know :c

[Solutions] Preliminary Round- Bangladesh Artificial Intelligence Olympiad

Man, I got frightened, the way ppl were solving the problems  was insane! :). I just barely submitted the Dora problem and then saw some of them submitted almost all the problems wtf :).

Anyways, I am giving away my solutions to the problems in this blog for the sake of humanity. :’)

I managed to solve 10 problems except the problem number J. I didn’t get enough time to think about the problem. Problem B consumed most of the time during the contest. The CPU limit was exceeded. And then the problem C was hilariously easy :). I dunno if I will get selected or not but I enjoyed the contest. I am in Dhaka currently and had a little knowledge about Python a month ago. I didn’t have access to a PC or Laptop. I practiced on my mobile and participated using my mobile and if I made it to nationals, I guess I will be the only one who reached nationals using only a mobile phone :).

If I get selected, I am planning that I will go to my home and start practicing the real thing. My parents don’t allow me to go home because I don’t study at all there :). I can use nationals as an excuse to go home and start solving problems in Kaggle. But still I don’t see any chances to see myself going to nationals πŸ™

Pro tip: if it says cpu limit exceeded try selecting pypy instead of python, it works sometimes. :’)

A. Dora the Explorer[solution]

import math
t = int(input())
for _ in range(t):
    m, n, d = map(float, input().split())
    one = d*d
    two = m*m + n*n
    three = one/two
    answer = math.sqrt(three)
    answer_fin = answer*60
    print(answer_fin)

B. Kaif the Conqueror[solution]



from collections import deque

directions = [(-1, 0),(1, 0),(0, -1),(0, 1)]

def conquer_states(m, n, k, grid):
    queue = deque()
   
    visited = [[False] * n for _ in range(m)]
    total_conquerable = 0

    for i in range(m):
        for j in range(n):
            if grid[i][j] == 1:
                total_conquerable += 1
               
            elif grid[i][j] == 2:
                queue.append((i, j))
                visited[i][j] = True
    day = 0
    states = []


    while queue and total_conquerable > 0:
        day += 1
       
        newly_conquered = 0
        for _ in range(len(queue)):
            x, y = queue.popleft()
            for dx, dy in directions:
                nx, ny = x + dx, y + dy
                if 0 <= nx < m and 0 <= ny < n and not visited[nx][ny] and grid[nx][ny] == 1:
                    visited[nx][ny] = True
                    queue.append((nx, ny))
                    newly_conquered += 1
                    total_conquerable -= 1
        states.append(newly_conquered)

    if total_conquerable == 0:
        if k - 1 < len(states):
            print(1, states[k - 1])
        else:
            print(1, 0)
    else:
        print(0)

m,n,k = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(m)]

#maybe this time will workkkkkkkkk plsssssss :))))
conquer_states(m, n, k,grid)

C. Parrot Ai[solution]

s = input()
print(s)

E. Nandan’s Problem[solution]

import math
def count_painting_comb(a, b, x, y):
    ans_gcd = math.gcd(x, y)
    x //= ans_gcd
    y //= ans_gcd
    return min(a // x, b // y)
a, b, x, y = map(int, input().split())   
print(count_painting_comb(a, b, x, y))   

F. Electric Odyssey[solution]

def answer(n, hs):
    energy = 0
    start_energy_min = 0
    for i in range(n - 1):
        energy_use_korse = hs[i] - hs[i + 1]
        energy = energy + energy_use_korse
        start_energy_min = min(start_energy_min, energy)
    return start_energy_min*(-1)
n = int(input())
hs = list(map(int, input().split()))
print(answer(n, hs))

G. SmartSum AI[solution]

import sys

data = sys.stdin.read().splitlines()
coin_n = int(data[0])
coin_value = list(map(int, data[1].split()))

total = sum(coin_value)
x = [0] * (total + 1)
x[0] = 1

for value in coin_value:
    for i in range(total, value - 1, -1):
        if x[i - value]:
            x[i] = 1

answer = [str(i) for i in range(1, total + 1) if x[i]]

sys.stdout.write(f"{len(answer)}\n")
sys.stdout.write(" ".join(answer) + "\n")

H. The Lost Explorer’s Riddle[solution]

import sys

sys.setrecursionlimit(2 * 10**6)

T = int(input())

for _ in range(T):
    N, M = map(int, input().split())
    graph = [[] for _ in range(N + 1)]
   
    for _ in range(M):
        u,v = map(int,input().split())
        graph[u].append(v)
        graph[v].append(u)

    visited = [False] * (N + 1)
    cycle_found = False

    def go_get_it_xd(a, b):
        visited[a] = True
        for c in graph[a]:
            if not visited[c]:
                if go_get_it_xd(c, a):
                    return True
            elif c != b:
                return True
        return False

    for i in range(1, N + 1):
        if not visited[i]:
            if go_get_it_xd(i, -1):
                cycle_found = True
                break

    if cycle_found:
        print("YES")
    else:
        print("NO")

I. Manage GPUs[solution]

def answer(n, t, time):
    def time_koto(mid_time):
        total = sum(mid_time // ki for ki in time)
        return total >= t

    low, high = 1, max(time) * t
    while low < high:
        mid = (low + high) // 2
        if time_koto(mid):
            high = mid
        else:
            low = mid + 1
    return low
   
n, t = map(int, input().split())
time = list(map(int, input().split()))
print(answer(n, t, time))

J. Intah AI [solution]

Parini vai eta :(, abar rest niye try korbo solve korte, parle update kore dibo!

K. Build The Stairs[solution]

n = int(input())
stair_h = list(map(int, input().split()))

h = 0

for i in range(n):
    if stair_h[i] - i > h:
        h = stair_h[i] - i
       
answer = 0

for i in range(n):
    answer += (h + i - stair_h[i])

print(answer)

L. Unbalanced[solution]

s = input().strip()
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        print(i + 1, i + 2)
        break
else:
    print(-1, -1)

6 responses to “[Solutions] Preliminary Round- Bangladesh Artificial Intelligence Olympiad”

  1. Brother, suppose there is a math problem, which is 2+2=?.
    Now if I write 4, I should be disqualified as I have the exact same solutions as others did.
    So should I write 22?😁
    (I think 8-10 students will be disqualified from the top 50)
    (Also not 50 people will have unique solutions, right?)
    (So what do you think, how will they detect plagiarism?)

    1. Dude, I don’t think they will check if our codes are generating the same answers, rather they will check if the way we are getting the answers are same or not, if they are same in every line, spaces, if they are found unnaturally identical they both will be disqualified. :’)

      (life is too short to worry about the results, just chill out XD)

      1. Bro chill, you are living the real frrrr

        BTW that is what I am telling, they will check code not output, also some code have only one approach, like problem c and e. Both of our solution were exactly the same for these two. But for other problems the story might be a little different.

        Aaand u r in 28th position so yeah, I can assure you that you will be qualified for the nationals. Don’t know about me tho

        1. πŸ‘‰πŸ‘ˆπŸ€²

          1. BRO! both you and I have been selected!! We should meet up in the nationals. Congratulations!!!!!!!!!!

          2. Sure man! I am eager to meet!

Leave a Reply to sazi Cancel reply

Your email address will not be published. Required fields are marked *