Skip to content

Commit 066a82f

Browse files
committed
Added W03+W04 materials
1 parent 5edad6b commit 066a82f

9 files changed

Lines changed: 319 additions & 7 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
## Harbour.Space BKK 2025 M02.
1+
## Harbour.Space Barcelona 2026 M07.
22

33
### Semester content:
44

55
[ContestID_W01]: https://contest.yandex.ru/contest/89570/?lang=en
66
[ContestID_W02]: https://contest.yandex.ru/contest/89713/?lang=en
77
[ContestID_W03]: https://contest.yandex.ru/contest/89746/?lang=en
8-
[ContestID_W04]: https://contest.yandex.ru/contest/<CID>/?lang=en
8+
[ContestID_W04]: https://contest.yandex.ru/contest/89837/?lang=en
99
[ContestID_W05]: https://contest.yandex.ru/contest/<CID>/?lang=en
1010
[ContestID_W06]: https://contest.yandex.ru/contest/<CID>/?lang=en
1111
[ContestID_W07]: https://contest.yandex.ru/contest/<CID>/?lang=en
@@ -16,7 +16,7 @@
1616
[WarmUp_test_W01]: https://forms.gle/8Ni31LJ6PUJoZeUa9
1717
[WarmUp_test_W02]: https://forms.gle/<form_id>
1818
[WarmUp_test_W03]: https://forms.gle/RsHUS3TFTxSzY4jJ7
19-
[WarmUp_test_W04]: https://forms.gle/<form_id>
19+
[WarmUp_test_W04]: https://forms.gle/hrsrzd2eLGfUwypd6
2020
[WarmUp_test_W05]: https://forms.gle/<form_id>
2121
[WarmUp_test_W06]: https://forms.gle/<form_id>
2222
[WarmUp_test_W07]: https://forms.gle/<form_id>
@@ -28,7 +28,7 @@
2828
[Slides_W01]: ../master/week01_linear_algorithms/HS.BCN.2026.Algo.Class01.pdf
2929
[Slides_W02]: ../master/week02_sorting_algorithms/HS.BCN.2026.Algo.Class02.pdf
3030
[Slides_W03]: ../master/week03_binary_search/HS.BCN.2026.Algo.Class03.pdf
31-
[Slides_W04]: ../master/week03_basic_data_structures/HS.BCN.2026.Algo.Class03.pdf
31+
[Slides_W04]: ../master/week04_basic_data_structures/HS.BCN.2026.Algo.Class04.pdf
3232
[Slides_W05]: ../master/week04_dynamic_programming/HS.BCN.2026.Algo.Class04.pdf
3333
[Slides_W06]: ../master/week05_knapsack/HS.BCN.2026.Algo.Class05.pdf
3434
[Slides_W07]: ../master/week06_kmp_heap/HS.BCN.2026.Algo.Class06.pdf
@@ -41,10 +41,10 @@
4141
| Week | Content | Slides | WarmUp test | Contest | Soft Deadline |
4242
|:------:|:-----------------------|:--------------------:|:-----------------------:|:------------------------:|:----------------------:|
4343
| 01 | Linear algorithms | [Slides][Slides_W01] | [Test][WarmUp_test_W01] | [Contest][ContestID_W01] | 03.02.2026 13:00 UTC+1 |
44-
| 02 | Sorting algorithms | [Slides][Slides_W02] | None | [Contest][ContestID_W02] | 04.02.2026 13:00 UTC+1 |
44+
| 02 | Sorting algorithms | [Slides][Slides_W02] | None | [Contest][ContestID_W02] | 05.02.2026 13:00 UTC+1 |
45+
| 02 | Binary search | [Slides][Slides_W03] | [Test][WarmUp_test_W03] | [Contest][ContestID_W03] | 05.02.2026 13:00 UTC+1 |
46+
| 03 | Basic Data sturctures | [Slides][Slides_W04] | [Test][WarmUp_test_W04] | [Contest][ContestID_W04] | 06.02.2026 13:00 UTC+1 |
4547
<!---
46-
| 02 | Binary search | [Slides][Slides_W02] | [Test][WarmUp_test_W03] | [Contest][ContestID_W03] | 05.02.2026 13:00 UTC+1 |
47-
| 03 | Basic Data sturctures | [Slides][Slides_W03] | [Test][WarmUp_test_W04] | [Contest][ContestID_W04] | 06.02.2026 13:00 UTC+1 |
4848
| 04 | Dynamic programming | [Slides][Slides_W04] | [Test][WarmUp_test_W05] | [Contest][ContestID_W05] | 09.02.2026 13:00 UTC+1 |
4949
| 05 | Knapsack problem | [Slides][Slides_W05] | [Test][WarmUp_test_W06] | [Contest][ContestID_W06] | 10.02.2026 13:00 UTC+1 |
5050
| 06 | KMP & Heap | [Slides][Slides_W06] | [Test][WarmUp_test_W07] | [Contest][ContestID_W07] | 11.02.2026 13:00 UTC+1 |
497 KB
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This is a template for problem Sigma-Trimpazation.
2+
3+
from time import time
4+
5+
# set the following flag to True to estimate execution time
6+
#
7+
# Exact execution time on you device may be different
8+
# from one on Yandex contest platform!
9+
#
10+
# The flag MUST be False when you are submitting your solution!
11+
estimate_execution_time = False
12+
13+
# Fixed parameters of quantum process:
14+
quantum_a = 7**5
15+
quantum_m = 2**31 - 1
16+
17+
18+
def analyze_trimpazation(n, m, q0):
19+
'''
20+
This function generates data with given parameters
21+
and calculates desired Y value.
22+
23+
You need to modify it to make it execute faster.
24+
You can check your progress using estimate_execution_time flag
25+
at the top of the file.
26+
'''
27+
m_div2 = m // 2
28+
q = q0
29+
30+
# generating x data:
31+
x = []
32+
for i in range(n):
33+
x_i = q % m - m_div2
34+
x.append(x_i)
35+
q = ((q * quantum_a) % quantum_m)
36+
37+
# sorting x data:
38+
x.sort()
39+
40+
# calculating sum:
41+
res = 0
42+
for i, v in enumerate(x):
43+
res += (i + 1) * v
44+
45+
return res
46+
47+
48+
if __name__ == '__main__':
49+
N, M, q0 = map(int, input().split())
50+
t = time()
51+
print(analyze_trimpazation(N, M, q0))
52+
if estimate_execution_time:
53+
print(f'Execution time = {time() - t:.8f} seconds')
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
def binsearch_exists(x, key):
2+
l = 0
3+
r = len(x)
4+
while r - l > 1:
5+
m = (l + r) // 2
6+
if x[m] <= key:
7+
l = m
8+
else:
9+
r = m
10+
return x[l] == key
11+
12+
13+
def binsearch_left(x, key):
14+
l = -1
15+
r = len(x)
16+
while r - l > 1:
17+
m = (l + r) // 2
18+
if x[m] < key:
19+
l = m
20+
else:
21+
r = m
22+
return r
23+
24+
25+
def binsearch_right(x, key):
26+
l = -1
27+
r = len(x)
28+
while r - l > 1:
29+
m = (l + r) // 2
30+
if x[m] <= key:
31+
l = m
32+
else:
33+
r = m
34+
return r
35+
36+
37+
N = int(input())
38+
x = list(map(int, input().split()))
39+
x = sorted(x)
40+
key = int(input())
41+
print("YES" if binsearch_exists(x, key) else "NO")

week03_binary_search/counting.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
def counting_sort(x):
2+
N = len(x)
3+
M = max(x) + 1
4+
a = [0] * M
5+
for v in x:
6+
a[v] += 1
7+
res = []
8+
for i in range(M):
9+
for j in range(a[i]):
10+
res.append(i)
11+
return res
12+
13+
14+
def counting_sort2(x):
15+
N = len(x)
16+
M = max(x) + 1
17+
c = [0] * M
18+
for v in x:
19+
c[v] += 1
20+
for i in range(1, M):
21+
c[i] += c[i - 1]
22+
# print(c)
23+
res = [None] * N
24+
for i in range(N):
25+
position = c[x[i]] - 1
26+
res[position] = x[i]
27+
c[x[i]] -= 1
28+
return res
29+
30+
31+
if __name__ == '__main__':
32+
N = int(input())
33+
x = list(map(int, input().split()))
34+
x = counting_sort2(x)
35+
print(' '.join(map(str, x)))

week03_binary_search/sqrt.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from math import sqrt as msqrt
2+
from random import random
3+
4+
def sqrt(x, eps):
5+
l = 0.
6+
r = max(1, float(x))
7+
while r - l > eps:
8+
m = (l + r) / 2
9+
if m ** 2 < x:
10+
l = m
11+
else:
12+
r = m
13+
return (l + r) / 2
14+
15+
16+
eps = 1e-8
17+
while True:
18+
x = random() * 100
19+
y1 = msqrt(x)
20+
y2 = sqrt(x, eps)
21+
if abs(y1 - y2) > eps:
22+
print(f'fail: {x:.9f}')
23+
exit(0)
24+
else:
25+
print('OK')
535 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This is input template for W3.C EyeQueue problem.
2+
3+
import sys
4+
5+
if __name__ == '__main__':
6+
# Uncomment these lines to use file input/output:
7+
# sys.stdin = open('input.txt', 'r')
8+
# sys.stdout = open('output.txt', 'r')
9+
10+
N = int(input())
11+
12+
# here comes initialization code if needed
13+
14+
for line in sys.stdin:
15+
cmd = line.split()
16+
c_i = cmd[0]
17+
q_i = int(cmd[1]) if len(cmd) > 1 else None
18+
id_i = int(cmd[2]) if len(cmd) > 2 else None
19+
20+
if c_i == '#':
21+
break
22+
elif c_i == '+':
23+
# Your code goes here
24+
pass
25+
elif c_i == '!':
26+
# Your code goes here
27+
pass
28+
elif c_i == '-':
29+
# Your code goes here
30+
pass
31+
elif c_i == '?':
32+
# Your code goes here
33+
pass
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
class ListNode:
2+
def __init__(self, val, next):
3+
self.val = val
4+
self.next = next
5+
6+
7+
class LinkedList:
8+
def __init__(self):
9+
# creating service node:
10+
self.head = ListNode(None, None)
11+
self.tail = self.head
12+
self.len = 0
13+
14+
def insert(self, previous_node, val):
15+
if not isinstance(previous_node, ListNode):
16+
raise TypeError("Expected previous_node to be"
17+
"ListNode instance")
18+
new_node = ListNode(val, previous_node.next)
19+
previous_node.next = new_node
20+
self.len += 1
21+
if new_node.next is None:
22+
self.tail = new_node
23+
return new_node
24+
25+
def push_front(self, val):
26+
return self.insert(self.head, val)
27+
28+
def push_back(self, val):
29+
return self.insert(self.tail, val)
30+
31+
def remove(self, node):
32+
if not isinstance(node, ListNode):
33+
raise TypeError("Expected node to be"
34+
"ListNode instance")
35+
if self.len < 1:
36+
raise ValueError('Trying to remove item from empty list')
37+
prev_node = self.head
38+
while prev_node is not None and prev_node.next != node:
39+
prev_node = prev_node.next
40+
if prev_node is not None:
41+
prev_node.next = node.next
42+
self.len -= 1
43+
if prev_node.next is None:
44+
self.tail = prev_node
45+
return node.val
46+
else:
47+
raise ValueError('Node provided to remove()'
48+
'was not found in the list')
49+
50+
def pop_back(self):
51+
return self.remove(self.tail)
52+
53+
def pop_front(self):
54+
# self.head.next may be Null. It is checked in self.remove()
55+
return self.remove(self.head.next)
56+
57+
def __len__(self):
58+
# This function is for using len(x).
59+
return self.len
60+
61+
# Following functions are just for easier debugging and testing:
62+
63+
def get_node_by_index(self, i):
64+
# Service node is supposed to be node 0
65+
if i < 0:
66+
i += self.len + 1
67+
if not (0 <= i <= self.len):
68+
raise IndexError('List index out of range')
69+
res = self.head
70+
for i in range(i):
71+
res = res.next
72+
return res
73+
74+
def insert_by_index(self, i, val):
75+
prev_node = self.get_node_by_index(i)
76+
return self.insert(prev_node, val)
77+
78+
def remove_by_index(self, i):
79+
node = self.get_node_by_index(i)
80+
self.remove(node.next)
81+
82+
def __getitem__(self, i):
83+
# This function is for using x[i].
84+
# We add 1 because self.get_node_by_index(0) returns service node
85+
return self.get_node_by_index(i + 1).val
86+
87+
def __repr__(self):
88+
# This function is for visualization.
89+
# It allows to use print() for List
90+
max_show = 10
91+
show_len = min(len(self), max_show)
92+
elements_repr = list(map(str, [self[i] for i in range(show_len)]))
93+
if len(self) > max_show:
94+
elements_repr.append('...')
95+
return f'List({len(self)} elements): [{", ".join(elements_repr)}]'
96+
97+
98+
if __name__ == '__main__':
99+
x = LinkedList()
100+
x.push_front(1)
101+
print(x)
102+
x.push_front(10)
103+
print(x)
104+
x.push_front(100)
105+
print(x)
106+
x.push_front(1000)
107+
print(x)
108+
x.insert_by_index(2, 5)
109+
print(x)
110+
x.insert_by_index(1, 7)
111+
print(x)
112+
x.insert_by_index(-1, 70)
113+
print(x)
114+
x.insert_by_index(-1, 80)
115+
print(x)
116+
x.insert_by_index(-2, 'Text')
117+
print(x)
118+
x.remove_by_index(2)
119+
print(x)
120+
x.pop_front()
121+
print(x)
122+
x.pop_back()
123+
print(x)
124+
x.push_back('Back')
125+
print(x)

0 commit comments

Comments
 (0)