├── README.md ├── cs_schools_oct_23 ├── statements.pdf └── jury_solutions │ ├── b.cs │ ├── a.cs │ ├── d.cs │ ├── c.cs │ └── e.cs ├── cs_schools_sep22 ├── statements.pdf └── jury_solutions │ ├── b.cs │ ├── a.cs │ ├── d.cs │ ├── c.cs │ └── e.cs ├── cs_schools_sep24 ├── statements.pdf └── jury_solutions │ ├── a.cs │ ├── c.cs │ ├── b.cs │ └── d.cs ├── internship_dec23 ├── statements.pdf └── jury_solutions │ ├── python │ ├── a.py │ ├── b.py │ ├── d.py │ └── c.py │ ├── cpp │ ├── a.cpp │ ├── d.cpp │ ├── b.cpp │ └── c.cpp │ └── cs │ ├── a.cs │ ├── d.cs │ ├── b.cs │ └── c.cs ├── internship_cs_feb22 ├── statements.pdf └── jury_solutions │ ├── a.cs │ ├── b.cs │ ├── d.cs │ ├── c.cs │ └── e.cs ├── internship_cs_mar23 ├── statements.pdf └── jury_solutions │ ├── python │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── e.py │ ├── cpp │ ├── a.cpp │ ├── c.cpp │ ├── d.cpp │ ├── b.cpp │ └── e.cpp │ ├── go │ ├── d.go │ ├── a.go │ ├── b.go │ ├── c.go │ └── e.go │ ├── cs │ ├── a.cs │ ├── d.cs │ ├── b.cs │ ├── c.cs │ └── e.cs │ └── java │ ├── TaskA.java │ ├── TaskD.java │ ├── TaskC.java │ ├── TaskE.java │ └── TaskB.java ├── internship_cs_mar24 ├── statements.pdf ├── jury_solutions │ ├── python │ │ ├── a.py │ │ ├── b.py │ │ ├── d.py │ │ ├── c.py │ │ └── e.py │ ├── cpp │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── d.cpp │ │ ├── c.cpp │ │ └── e.cpp │ ├── go │ │ ├── a.go │ │ ├── b.go │ │ ├── d.go │ │ ├── e.go │ │ └── c.go │ ├── cs │ │ ├── a.cs │ │ ├── b.cs │ │ ├── d.cs │ │ ├── c.cs │ │ └── e.cs │ └── java │ │ ├── TaskA.java │ │ ├── TaskB.java │ │ ├── TaskD.java │ │ └── TaskC.java └── Дорешивание.txt ├── internship_cs_nov21 ├── statements.pdf └── jury_solutions │ ├── b.cs │ ├── a.cs │ ├── c.cs │ ├── d.cs │ └── e.cs ├── hiring_days_cs_nov21 ├── statements.pdf └── jury_solutions │ ├── a.cs │ ├── b.cs │ ├── c_slow.cs │ ├── c.cs │ └── d.cs ├── hiring_days_cs_nov23 ├── statements.pdf └── jury_solutions │ ├── a.cs │ ├── d.cs │ ├── b.cs │ ├── e.cs │ └── c.cs ├── internship_backend_apr25 ├── statements.pdf └── jury_solutions │ ├── python │ ├── b.py │ ├── c.py │ ├── a.py │ └── d.py │ ├── cs │ ├── b.cs │ ├── c.cs │ ├── a.cs │ └── d.cs │ ├── java │ ├── B.java │ ├── C.java │ ├── A.java │ └── D.java │ ├── cpp │ ├── b.cpp │ ├── c.cpp │ ├── a.cpp │ └── d.cpp │ └── go │ ├── b.go │ ├── c.go │ ├── a.go │ ├── d.go │ └── e.go └── internship_backend_nov24 ├── statements.pdf └── jury_solutions ├── python ├── a.py ├── b.py ├── c.py ├── d.py └── e.py ├── cpp ├── b.cpp ├── a.cpp ├── c.cpp ├── d.cpp └── e.cpp ├── cs ├── a.cs ├── b.cs ├── c.cs ├── d.cs └── e.cs ├── go ├── a.go ├── c.go ├── b.go ├── d.go └── e.go └── java ├── A.java ├── C.java ├── B.java ├── D.java └── E.java /README.md: -------------------------------------------------------------------------------- 1 | Здесь будут размещаться материалы по контестам, которые проводит Контур 2 | -------------------------------------------------------------------------------- /cs_schools_oct_23/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/cs_schools_oct_23/statements.pdf -------------------------------------------------------------------------------- /cs_schools_sep22/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/cs_schools_sep22/statements.pdf -------------------------------------------------------------------------------- /cs_schools_sep24/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/cs_schools_sep24/statements.pdf -------------------------------------------------------------------------------- /internship_dec23/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/internship_dec23/statements.pdf -------------------------------------------------------------------------------- /internship_cs_feb22/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/internship_cs_feb22/statements.pdf -------------------------------------------------------------------------------- /internship_cs_mar23/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/internship_cs_mar23/statements.pdf -------------------------------------------------------------------------------- /internship_cs_mar24/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/internship_cs_mar24/statements.pdf -------------------------------------------------------------------------------- /internship_cs_nov21/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/internship_cs_nov21/statements.pdf -------------------------------------------------------------------------------- /hiring_days_cs_nov21/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/hiring_days_cs_nov21/statements.pdf -------------------------------------------------------------------------------- /hiring_days_cs_nov23/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/hiring_days_cs_nov23/statements.pdf -------------------------------------------------------------------------------- /internship_backend_apr25/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/internship_backend_apr25/statements.pdf -------------------------------------------------------------------------------- /internship_backend_nov24/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/contests/HEAD/internship_backend_nov24/statements.pdf -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/python/a.py: -------------------------------------------------------------------------------- 1 | n, t = map(int, input().split()) 2 | if sum(map(int, input().split())) <= t <= sum(map(int, input().split())): 3 | print('YES') 4 | else: 5 | print('NO') 6 | -------------------------------------------------------------------------------- /internship_cs_mar24/Дорешивание.txt: -------------------------------------------------------------------------------- 1 | Дорешивание контеста доступно по ссылке: https://codeforces.com/contestInvitation/48a4d3407dfb2a7e0849c713911b8a71162e2d22 2 | 3 | Дорешивание не влияет на результаты контеста. 4 | -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/python/a.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | res = '' 3 | mx = -1 4 | for i in range(n): 5 | s = input() 6 | unique = len(set(s)) 7 | if unique > mx: 8 | mx = unique 9 | res = s 10 | print(mx, res, sep = ' ') 11 | -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/python/a.py: -------------------------------------------------------------------------------- 1 | n1, n2 = map(int, input().split()) 2 | 3 | common = min(n1, n2) 4 | ans = 3 * common 5 | n1 -= common 6 | n2 -= common 7 | 8 | if n2 > 0: 9 | ans += 2 10 | elif n1 > 0: 11 | ans += 1 12 | 13 | print(ans) 14 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/python/a.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | f = list(map(int, input().split())) 3 | mx, mn = 0, 0; 4 | for i in range(n): 5 | if f[i] >= f[mx]: 6 | mx = i 7 | if f[i] < f[mn]: 8 | mn = i 9 | 10 | print(mx + 1, mn + 1) 11 | -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/cpp/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b; 7 | cin >> a >> b; 8 | if(a == b) 9 | cout << 3 * a; 10 | else if(a < b) cout << 3 * a + 2; 11 | else cout << 3 * b + 1; 12 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/python/b.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | n = len(s) 3 | arr = [int(c) for c in s] 4 | ans = n 5 | for k in range(1, n + 1): 6 | if n % k: 7 | continue 8 | res = 0 9 | for i in range(n): 10 | res += (i // k % 2) != arr[i] 11 | ans = min(ans, res, n - res) 12 | print(ans) -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/python/b.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | throwsX = 0 3 | throwsY = 0 4 | for i in range(n): 5 | x, y = map(int, input().split()) 6 | throwsX -= x 7 | throwsY -= y 8 | for i in range(n): 9 | x, y = map(int, input().split()) 10 | throwsX += x 11 | throwsY += y 12 | print(throwsX // n, throwsY // n) 13 | -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/python/b.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | numbers = input().split() 3 | s = sum([int(x) for x in numbers]) 4 | 5 | current_sum = 0 6 | for i in range(n - 1): 7 | current_sum += int(numbers[i]) 8 | if 2 * current_sum == s: 9 | print('+'.join(numbers[:i + 1]), '=', '+'.join(numbers[i + 1:]), sep='') 10 | exit() 11 | 12 | print(-1) 13 | -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/python/d.py: -------------------------------------------------------------------------------- 1 | n, k = map(int, input().split()) 2 | s = input() 3 | ans = 0 4 | for ch in 'RGB': 5 | cur, l = 0, 0 6 | for i in range(n): 7 | if ch != s[i]: 8 | cur += 1 9 | while l < i and cur > k: 10 | if ch != s[l]: 11 | cur -= 1 12 | l += 1 13 | ans = max(ans, i - l + 1) 14 | print(ans) 15 | -------------------------------------------------------------------------------- /cs_schools_sep22/jury_solutions/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace ConsoleApp 5 | { 6 | class Program 7 | { 8 | public static void Main() 9 | { 10 | int n = int.Parse(Console.ReadLine()); 11 | int sum = 0; 12 | for (int i = 0; i < n; i++) 13 | { 14 | int x = int.Parse(Console.ReadLine()); 15 | sum += x; 16 | } 17 | Console.WriteLine(-sum); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/python/b.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | f = [tuple(map(int, input().split())) for _ in range(n)] 3 | s = set(f) 4 | ans = 0 5 | for i in range(n): 6 | for j in range(i + 1, n): 7 | area = abs(f[i][0] - f[j][0]) * abs(f[i][1] - f[j][1]) 8 | if area <= ans: continue 9 | if (f[i][0], f[j][1]) in s and (f[j][0], f[i][1]) in s: 10 | ans = area 11 | print(ans) 12 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/python/c.py: -------------------------------------------------------------------------------- 1 | n, k = map(int, input().split()) 2 | arr = list(map(int, input().split())) 3 | 4 | l, zeros, sm, ans = 0, 0, 0, 0 5 | for r in range(n): 6 | sm += arr[r] 7 | zeros += arr[r] == 0 8 | while sm > k or zeros > 1: 9 | zeros -= arr[l] == 0 10 | sm -= arr[l] 11 | l += 1 12 | if sm <= k and zeros < 2: 13 | ans += r - l + 1 14 | print(ans) 15 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/python/d.py: -------------------------------------------------------------------------------- 1 | ans = 0 2 | 3 | def rec(last = 0, cur = 0): 4 | if cur in h[last]: return 5 | h[last].add(cur) 6 | if last == n: 7 | global ans 8 | ans += 1 9 | return 10 | for val in f[last]: 11 | rec(last + 1, cur + val) 12 | 13 | n = int(input()) 14 | h = [set() for _ in range(n + 1)] 15 | f = [list(map(int, input().split())) for _ in range(n)] 16 | rec() 17 | print(ans) 18 | -------------------------------------------------------------------------------- /cs_schools_sep22/jury_solutions/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace ConsoleApp 5 | { 6 | class Program 7 | { 8 | public static void Main() 9 | { 10 | var s = Console.ReadLine(); 11 | var charArray = s.ToCharArray(); 12 | var m = string.Concat(charArray.OrderBy(c => c)); 13 | var M = string.Concat(charArray.OrderByDescending(c => c)); 14 | Console.WriteLine(int.Parse(M) - int.Parse(m)); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cpp/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define int long long 4 | 5 | using namespace std; 6 | 7 | signed main() { 8 | int n, t; 9 | cin >> n >> t; 10 | int L = 0, R = 0, a, b; 11 | for (int i = 0; i < n; ++i) cin >> a, L += a; 12 | for (int i = 0; i < n; ++i) cin >> b, R += b; 13 | if (L <= t && t <= R) 14 | cout << "YES\n"; 15 | else 16 | cout << "NO\n"; 17 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cpp/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | int n; 8 | cin >> n; 9 | vector f(n); 10 | int mx = 0, mn = 0; 11 | for(int i = 0; i < n; ++i){ 12 | cin >> f[i]; 13 | if(f[i] >= f[mx]) 14 | mx = i; 15 | 16 | if(f[i] < f[mn]) 17 | mn = i; 18 | } 19 | cout << mx + 1 << ' ' << mn + 1; 20 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cpp/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string s; 7 | cin >> s; 8 | int n = s.length(); 9 | int ans = n; 10 | for (int k = 1; k <= n; ++k) { 11 | if (n % k) continue; 12 | int res = 0; 13 | for (int i = 0; i < n; ++i) 14 | res += (i / k % 2) != (s[i] - '0'); 15 | ans = min(ans, min(res, n - res)); 16 | } 17 | cout << ans; 18 | } -------------------------------------------------------------------------------- /hiring_days_cs_nov23/jury_solutions/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Int32; 3 | 4 | public static void Main() 5 | { 6 | var input = Console.ReadLine().Split(); 7 | var oneCount = Parse(input[0]); 8 | var twoCount = Parse(input[1]); 9 | if (oneCount == twoCount) 10 | Console.WriteLine(oneCount + twoCount * 2); 11 | else if (oneCount > twoCount) 12 | Console.WriteLine(twoCount + 1 + twoCount * 2); 13 | else 14 | Console.WriteLine(oneCount + (oneCount + 1) * 2); 15 | } -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/cs/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Int32; 3 | 4 | public static void Main() 5 | { 6 | var input = Console.ReadLine().Split(); 7 | var oneCount = Parse(input[0]); 8 | var twoCount = Parse(input[1]); 9 | if (oneCount == twoCount) 10 | Console.WriteLine(oneCount + twoCount * 2); 11 | else if (oneCount > twoCount) 12 | Console.WriteLine(twoCount + 1 + twoCount * 2); 13 | else 14 | Console.WriteLine(oneCount + (oneCount + 1) * 2); 15 | } -------------------------------------------------------------------------------- /hiring_days_cs_nov21/jury_solutions/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | 4 | namespace ConsoleApp 5 | { 6 | class Program 7 | { 8 | static void Main() 9 | { 10 | var n = int.Parse(Console.ReadLine()); 11 | var result = TimeSpan.Zero; 12 | for (int i = 0; i < n; i++) 13 | { 14 | var s = Console.ReadLine(); 15 | var time = TimeSpan.ParseExact(s, "mm\\:ss", CultureInfo.InvariantCulture); 16 | result += time; 17 | } 18 | 19 | Console.WriteLine(result); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /internship_cs_feb22/jury_solutions/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace ConsoleApp 5 | { 6 | static class Program 7 | { 8 | static void Main() 9 | { 10 | var ints = Console.ReadLine().Split().Select(int.Parse).ToArray(); 11 | 12 | int maxCount = Math.Max(ints[0], ints[1]); 13 | int minCount = Math.Min(ints[0], ints[1]); 14 | 15 | for (int i = 1; ; i++) 16 | { 17 | if (i * i / 2 > minCount || (i * i + 1) / 2 > maxCount) 18 | { 19 | Console.WriteLine(i - 1); 20 | return; 21 | } 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/python/d.py: -------------------------------------------------------------------------------- 1 | pattern = ''.join(chr(ch) + chr(ch).upper() for ch in range(ord('a'), ord('z') + 1)) 2 | 3 | sz = len(pattern) 4 | pos = dict((pattern[i], i) for i in range(sz)) 5 | 6 | s = input() 7 | n = len(s) 8 | t = [pos[s[i]] for i in range(n)] 9 | f = [0] * (n + 1) 10 | q = int(input()) 11 | for _ in range(q): 12 | l, r, x = map(int, input().split()) 13 | f[l - 1] += x 14 | f[r] -= x 15 | for i in range(1, n): 16 | f[i] += f[i - 1] 17 | print(''.join(pattern[(t[i] + f[i]) % sz] for i in range(n))) 18 | -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/python/c.py: -------------------------------------------------------------------------------- 1 | n, m = [int(x) for x in input().split()] 2 | t = int(input()) 3 | 4 | rows = [(-1, 0)] * n 5 | columns = [(-1, 0)] * m 6 | 7 | for i in range(t): 8 | x, y, c = [int(x) for x in input().split()] 9 | rows[x - 1] = (i, c) 10 | columns[y - 1] = (i, c) 11 | 12 | for i in range(n): 13 | list = [] 14 | for j in range(m): 15 | if rows[i][0] < columns[j][0]: 16 | list.append(str(columns[j][1])) 17 | else: 18 | list.append(str(rows[i][1])) 19 | print(' '.join(list)) 20 | -------------------------------------------------------------------------------- /internship_cs_nov21/jury_solutions/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace ConsoleApp 5 | { 6 | static class Program 7 | { 8 | static void Main() 9 | { 10 | var password = Console.ReadLine(); 11 | int letters = password.Count(char.IsLetter); 12 | int digits = password.Count(char.IsDigit); 13 | 14 | if (password.Length >= 7 15 | && letters >= 2 16 | && digits >= 2 17 | && password.Length - letters - digits >= 1) 18 | Console.WriteLine("GOOD"); 19 | else 20 | Console.WriteLine("BAD"); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/go/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | var n, t int64 11 | fmt.Scan(&n, &t) 12 | 13 | in := bufio.NewReader(os.Stdin) 14 | 15 | var sum_a, sum_b int64 16 | var a, b int64 17 | for i := int64(0); i < n; i++ { 18 | fmt.Fscan(in, &a) 19 | sum_a += a 20 | } 21 | 22 | for i := int64(0); i < n; i++ { 23 | fmt.Fscan(in, &b) 24 | sum_b += b 25 | } 26 | 27 | if t >= sum_a && t <= sum_b { 28 | fmt.Println("YES") 29 | } else { 30 | fmt.Println("NO") 31 | } 32 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cpp/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n, k; 8 | cin >> n >> k; 9 | vector arr(n); 10 | for (int i = 0; i < n; ++i) 11 | cin >> arr[i]; 12 | int l = 0, zeros = 0; 13 | long long sum = 0, ans = 0; 14 | for (int r = 0; r < n; ++r) { 15 | sum += arr[r]; 16 | zeros += arr[r] == 0; 17 | while (sum > k || zeros > 1) { 18 | zeros -= arr[l] == 0; 19 | sum -= arr[l++]; 20 | } 21 | if(sum <= k && zeros < 2) 22 | ans += r - l + 1; 23 | } 24 | cout << ans; 25 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cpp/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n; 5 | std::cin >> n; 6 | long long throwsX = 0L; 7 | long long throwsY = 0L; 8 | 9 | for (int i = 0; i < n; i++) { 10 | long long x, y; 11 | std::cin >> x >> y; 12 | throwsX -= x; 13 | throwsY -= y; 14 | } 15 | 16 | for (int i = 0; i < n; i++) { 17 | long long x, y; 18 | std::cin >> x >> y; 19 | throwsX += x; 20 | throwsY += y; 21 | } 22 | 23 | std::cout << throwsX / n << ' ' << throwsY / n; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/cpp/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, k; 7 | cin >> n >> k; 8 | string s; 9 | cin >> s; 10 | string all = "RGB"; 11 | int ans = 0; 12 | for(char ch : all) { 13 | int cur = 0, l = 0; 14 | for(int i = 0; i < n; ++i) { 15 | if(ch != s[i]) 16 | ++cur; 17 | while(l < i && cur > k) { 18 | if(ch != s[l]) 19 | --cur; 20 | ++l; 21 | } 22 | ans = max(ans, i - l + 1); 23 | } 24 | } 25 | cout << ans; 26 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/go/d.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | reader := bufio.NewReader(os.Stdin) 11 | 12 | var n int 13 | fmt.Fscan(reader, &n) 14 | 15 | possible := make(map[int]bool) 16 | possible[0] = true 17 | 18 | for i := 0; i < n; i++ { 19 | newPossible := make(map[int]bool) 20 | 21 | for j := 0; j < 6; j++ { 22 | var next int 23 | fmt.Fscan(reader, &next) 24 | 25 | for k := range possible { 26 | newPossible[k+next] = true 27 | } 28 | } 29 | 30 | possible = newPossible 31 | } 32 | 33 | fmt.Println(len(possible)) 34 | } 35 | -------------------------------------------------------------------------------- /internship_cs_nov21/jury_solutions/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace ConsoleApp 5 | { 6 | class Program 7 | { 8 | static void Main() 9 | { 10 | var answer = "rgby".ToDictionary(ch => ch, ch => 0); 11 | for (int i = 1; i < 10; i++) 12 | for (int j = 1; j < 10; j++) 13 | { 14 | var p = i * j; 15 | if (p % 2 == 0) 16 | answer['r']++; 17 | else if (p % 3 == 0) 18 | answer['g']++; 19 | else if (p % 5 == 0) 20 | answer['b']++; 21 | else 22 | answer['y']++; 23 | } 24 | 25 | var color = Console.ReadLine()[0]; 26 | Console.WriteLine(answer[color]); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/python/c.py: -------------------------------------------------------------------------------- 1 | size, border, changes = map(int, input().split()) 2 | elements = list(map(int, input().split())) 3 | left = 0 4 | right = 0 5 | currentChanges = 0 6 | maxLength = 0 7 | while (right < size): 8 | if elements[right] < border: 9 | right += 1 10 | continue 11 | if currentChanges < changes: 12 | currentChanges += 1 13 | right += 1 14 | continue 15 | maxLength = max(maxLength, right - left) 16 | 17 | while elements[left] < border: 18 | left += 1 19 | 20 | left += 1 21 | right += 1 22 | maxLength = max(maxLength, right - left) 23 | print(maxLength) 24 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cs/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Summer2024 5 | { 6 | public static class Program 7 | { 8 | public static void Main() 9 | { 10 | var nt = ReadLongArray(); 11 | var n = nt[0]; 12 | var t = nt[1]; 13 | 14 | var a = ReadLongArray(); 15 | var b = ReadLongArray(); 16 | 17 | var result = a.Sum() <= t && t <= b.Sum(); 18 | Console.WriteLine(result ? "Yes" : "No"); 19 | } 20 | 21 | public static long[] ReadLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray(); 22 | } 23 | } -------------------------------------------------------------------------------- /cs_schools_oct_23/jury_solutions/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | class Program 5 | { 6 | public static void Main() 7 | { 8 | var _ = Console.ReadLine(); 9 | var sequence = Console.ReadLine(); 10 | var totalDisabledCount = sequence.Count(e => e.Equals('0')); 11 | 12 | var answer = totalDisabledCount; 13 | var enabledCount = 0; 14 | var disabledCount = 0; 15 | 16 | foreach (var isEnable in sequence.Select(e => e.Equals('1'))) 17 | { 18 | if (isEnable) 19 | enabledCount++; 20 | else 21 | disabledCount++; 22 | answer = Math.Min(answer, enabledCount + totalDisabledCount - disabledCount); 23 | } 24 | 25 | Console.WriteLine(answer); 26 | } 27 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cpp/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int ans = 0, n; 8 | vector> f; 9 | vector> h; 10 | 11 | void rec(int last = 0, int cur = 0) { 12 | if (h[last].count(cur)) return; 13 | h[last].insert(cur); 14 | if (last == n) 15 | return void(++ans); 16 | for (int i = 0; i < 6; ++i) 17 | rec(last + 1, cur + f[last][i]); 18 | } 19 | 20 | signed main() { 21 | cin >> n; 22 | f.resize(n, vector(6)); 23 | h.resize(n + 1); 24 | for (int i = 0; i < n; ++i) 25 | for (int j = 0; j < 6; ++j) 26 | cin >> f[i][j]; 27 | rec(); 28 | cout << ans; 29 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cpp/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n; 5 | std::cin >> n; 6 | std::string res = ""; 7 | int mx = INT_MIN; 8 | while (n--) { 9 | std::string s; 10 | std::cin >> s; 11 | std::vector charsCount(40, 0); 12 | 13 | int unique = 0; 14 | 15 | for (auto& i : s) 16 | charsCount[i - 'a']++; 17 | 18 | for (auto& i : charsCount) 19 | unique += i == 0 ? 0 : 1; 20 | 21 | if (unique > mx) { 22 | res = s; 23 | mx = unique; 24 | } 25 | } 26 | 27 | std::cout << mx << ' ' << res; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cs/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | 5 | class Program 6 | { 7 | static void Main() 8 | { 9 | Solve(); 10 | } 11 | 12 | static void Solve() 13 | { 14 | int n = int.Parse(Console.ReadLine()); 15 | 16 | int max = -1; 17 | string res = ""; 18 | 19 | for (int i = 0; i < n; i++) 20 | { 21 | var s = Console.ReadLine(); 22 | int unique = s.Distinct().Count(); 23 | 24 | if (unique > max) 25 | { 26 | res = s; 27 | max = unique; 28 | } 29 | } 30 | 31 | Console.WriteLine($"{max} {res}"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/go/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | var count int 11 | 12 | reader := bufio.NewReader(os.Stdin) 13 | fmt.Fscan(reader, &count) 14 | brNums := make([]int, count) 15 | 16 | for i := 0; i < count; i++ { 17 | var br int 18 | fmt.Fscan(reader, &br) 19 | brNums[i] = br 20 | } 21 | 22 | iMin := 0 23 | iMax := 0 24 | min := brNums[0] 25 | max := brNums[0] 26 | 27 | for i, num := range brNums { 28 | if num < min { 29 | min = num 30 | iMin = i 31 | } 32 | if num >= max { 33 | max = num 34 | iMax = i 35 | } 36 | } 37 | 38 | fmt.Println(iMax + 1, iMin + 1) 39 | } 40 | -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/python/d.py: -------------------------------------------------------------------------------- 1 | from bisect import bisect_left 2 | 3 | maxX, maxY = map(int, input().split()) 4 | xCount, yCount = map(int, input().split()) 5 | xLines = list(map(int, input().split())) 6 | yLines = list(map(int, input().split())) 7 | queriesCount = int(input()) 8 | xLines.append(0) 9 | xLines.append(maxX) 10 | yLines.append(0) 11 | yLines.append(maxY) 12 | xLines.sort() 13 | yLines.sort() 14 | for _ in range(queriesCount): 15 | x1, y1, x2, y2 = map(int, input().split()) 16 | diffX = bisect_left(xLines, x1) == bisect_left(xLines, x2) 17 | diffY = bisect_left(yLines, y1) == bisect_left(yLines, y2) 18 | if diffX and diffY: 19 | print("YES") 20 | else: 21 | print("NO") 22 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cs/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Summer2024 4 | { 5 | public static class Program 6 | { 7 | public static void Main() 8 | { 9 | var a = Console.ReadLine(); 10 | var n = a.Length; 11 | var ans = n; 12 | 13 | for (var k = 1; k <= n; k++) { 14 | if (n % k > 0) continue; 15 | var result = 0; 16 | for (var i = 0; i < n; ++i) 17 | result += (i / k % 2) != (a[i] - '0') ? 1 : 0; 18 | 19 | ans = Math.Min(ans, Math.Min(result, n - result)); 20 | } 21 | 22 | Console.WriteLine(ans); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /cs_schools_sep24/jury_solutions/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class Solution 4 | { 5 | static void Main() 6 | { 7 | new Solution().Run(); 8 | } 9 | 10 | int GetDistance(int start, int l, int r) 11 | { 12 | if (l == -1) 13 | return 0; 14 | if (r < start) 15 | return start - l; 16 | if (l > start) 17 | return r - start; 18 | return Math.Min((start - l) * 2 + (r - start), (start - l) + (r - start) * 2); 19 | } 20 | 21 | void Run() 22 | { 23 | var s = Console.ReadLine(); 24 | int start = s.IndexOf('O'); 25 | int left = s.IndexOf('X'); 26 | int right = s.LastIndexOf('X'); 27 | Console.WriteLine(GetDistance(start, left, right)); 28 | } 29 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/python/b.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | _ = input() # Игнорируем первую строку ввода 3 | houses = list(map(int, input().split())) 4 | heaters = list(map(int, input().split())) 5 | 6 | min_radius = [float('inf')] * len(houses) 7 | 8 | j = 0 9 | k = 0 10 | 11 | houses.sort() 12 | heaters.sort() 13 | 14 | while j < len(houses): 15 | min_radius[j] = min(min_radius[j], abs(houses[j] - heaters[k])) 16 | 17 | if k > 0: 18 | min_radius[j] = min(min_radius[j], abs(houses[j] - heaters[k - 1])) 19 | 20 | if heaters[k] < houses[j] and k < len(heaters) - 1: 21 | k += 1 22 | else: 23 | j += 1 24 | 25 | print(max(min_radius)) 26 | 27 | if __name__ == "__main__": 28 | main() -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cpp/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | signed main() { 8 | int n; 9 | cin >> n; 10 | vector> f(n); 11 | set> s; 12 | for (int i = 0; i < n; ++i) { 13 | cin >> f[i].first >> f[i].second; 14 | s.insert(f[i]); 15 | } 16 | long long ans = 0; 17 | for (int i = 0; i < n; ++i) { 18 | for (int j = i + 1; j < n; ++j) { 19 | long long area = (long long)abs(f[i].first - f[j].first) * 20 | abs(f[i].second - f[j].second); 21 | if (area <= ans) continue; 22 | pair a(f[i].first, f[j].second); 23 | pair b(f[j].first, f[i].second); 24 | if (s.count(a) && s.count(b)) 25 | ans = area; 26 | } 27 | } 28 | cout << ans; 29 | } 30 | -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/cpp/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | vector f(n); 10 | int all_sum = 0; 11 | for(int i = 0; i < n; ++i) cin >> f[i], all_sum += f[i]; 12 | int cur_sum = 0, border = -1; 13 | for(int i = 0; i < n; ++i) { 14 | cur_sum += f[i]; 15 | if(cur_sum == all_sum - cur_sum) { 16 | border = i; 17 | break; 18 | } 19 | } 20 | if(border == -1) { 21 | cout << -1; 22 | return 0; 23 | } 24 | cout << f[0]; 25 | for(int i = 1; i <= border; ++i) cout << '+' << f[i]; 26 | cout << "="; 27 | for(int i = border + 1; i + 1 < n; ++i) cout << f[i] << '+'; 28 | cout << f[n - 1]; 29 | } -------------------------------------------------------------------------------- /hiring_days_cs_nov21/jury_solutions/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace ConsoleApp 5 | { 6 | class Program 7 | { 8 | static void Main() 9 | { 10 | var ints = Console.ReadLine() 11 | .Split() 12 | .Select(int.Parse) 13 | .ToList(); 14 | int n = ints[0]; 15 | int m = ints[1]; 16 | var map = new string[n]; 17 | for (int i = 0; i < n; i++) 18 | { 19 | map[i] = Console.ReadLine(); 20 | } 21 | 22 | int result = 0; 23 | 24 | for (int i = 0; i < n; i++) 25 | for (int j = 0; j < m; j++) 26 | { 27 | if (map[i][j] == '.') 28 | { 29 | if (i + 1 < n && map[i + 1][j] == '.') 30 | result++; 31 | if (j + 1 < m && map[i][j + 1] == '.') 32 | result++; 33 | } 34 | } 35 | 36 | Console.WriteLine(result); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cs/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | 5 | class Program 6 | { 7 | static void Main() 8 | { 9 | Solve(); 10 | } 11 | 12 | static void Solve() 13 | { 14 | int n = int.Parse(Console.ReadLine()); 15 | var throwsX = 0L; 16 | var throwsY = 0L; 17 | 18 | for (int i = 0; i < n; i++) 19 | { 20 | var longs = Console.ReadLine().Split().Select(long.Parse).ToArray(); 21 | throwsX -= longs[0]; 22 | throwsY -= longs[1]; 23 | } 24 | 25 | for (int i = 0; i < n; i++) 26 | { 27 | var longs = Console.ReadLine().Split().Select(long.Parse).ToArray(); 28 | throwsX += longs[0]; 29 | throwsY += longs[1]; 30 | } 31 | 32 | Console.WriteLine($"{throwsX / n} {throwsY / n}"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /hiring_days_cs_nov23/jury_solutions/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public static class Program 5 | { 6 | public static void Main() 7 | { 8 | var k = Console.ReadLine().Split().Select(int.Parse).ToArray()[1]; 9 | var s = Console.ReadLine(); 10 | var ans = 0; 11 | foreach (var c in new[] {'R', 'G', 'B'}) 12 | { 13 | var replacesCount = 0; 14 | var start = 0; 15 | for (var i = 0; i < s.Length; i++) 16 | { 17 | if (s[i] != c) 18 | replacesCount++; 19 | while (replacesCount > k && start < i) 20 | if (s[start++] != c) 21 | replacesCount--; 22 | ans = Math.Max(ans, i - start + 1); 23 | } 24 | } 25 | Console.WriteLine(ans); 26 | } 27 | } -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/cs/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public static class Program 5 | { 6 | public static void Main() 7 | { 8 | var k = Console.ReadLine().Split().Select(int.Parse).ToArray()[1]; 9 | var s = Console.ReadLine(); 10 | var ans = 0; 11 | foreach (var c in new[] {'R', 'G', 'B'}) 12 | { 13 | var replacesCount = 0; 14 | var start = 0; 15 | for (var i = 0; i < s.Length; i++) 16 | { 17 | if (s[i] != c) 18 | replacesCount++; 19 | while (replacesCount > k && start < i) 20 | if (s[start++] != c) 21 | replacesCount--; 22 | ans = Math.Max(ans, i - start + 1); 23 | } 24 | } 25 | Console.WriteLine(ans); 26 | } 27 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cs/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | 6 | namespace ConsoleApp2 7 | { 8 | public class Program 9 | { 10 | private static void Solve() 11 | { 12 | int n = int.Parse(Console.ReadLine()); 13 | var a = ReadInts(); 14 | var elems = new List<(int, int)>(); 15 | for (int i = 0; i < n; i++) 16 | { 17 | elems.Add((a[i], i)); 18 | } 19 | 20 | elems.Sort(); 21 | Console.WriteLine($"{elems.Last().Item2 + 1} {elems.First().Item2 + 1}"); 22 | } 23 | 24 | 25 | public static void Main() 26 | { 27 | var T = new Thread(Solve, 10000000); 28 | T.Start(); 29 | } 30 | 31 | private static int[] ReadInts() 32 | { 33 | return Console.ReadLine() 34 | .Split() 35 | .Select(int.Parse) 36 | .ToArray(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /internship_cs_nov21/jury_solutions/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | static class Program 8 | { 9 | static void Main() 10 | { 11 | Console.ReadLine(); 12 | var numbers = Console.ReadLine() 13 | .Split() 14 | .Select(int.Parse) 15 | .ToArray(); 16 | 17 | var oppositeElements = FindOppositeElements(numbers); 18 | Console.WriteLine($"{oppositeElements.Item1} {oppositeElements.Item2}"); 19 | } 20 | 21 | private static (int, int) FindOppositeElements(int[] numbers) 22 | { 23 | var lastIndex = new Dictionary(); 24 | int i = 1; 25 | foreach (var x in numbers) 26 | { 27 | if (lastIndex.ContainsKey(-x)) 28 | return (i, lastIndex[-x]); 29 | 30 | lastIndex[x] = i; 31 | i++; 32 | } 33 | 34 | return (0, 0); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /cs_schools_oct_23/jury_solutions/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | class Program 5 | { 6 | public static void Main() 7 | { 8 | var sizes = Console.ReadLine().Split().Select(int.Parse).ToArray(); 9 | var result = 0; 10 | 11 | // Сгибаем лист строго по клеточкам и пополам по первому направлению 12 | // Это можно делать до тех пор, пока количество клеток делится на 2 13 | while (sizes[0] % 2 == 0) 14 | { 15 | result++; 16 | sizes[0] /= 2; 17 | } 18 | 19 | // Сгибаем лист строго по клеточкам и пополам по второму направлению 20 | // Это можно делать до тех пор, пока количество клеток делится на 2 21 | while (sizes[1] % 2 == 0) 22 | { 23 | result++; 24 | sizes[1] /= 2; 25 | } 26 | 27 | Console.WriteLine(result); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/go/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func main() { 9 | err := TaskA() 10 | if err != nil { 11 | fmt.Printf("err: %s", err.Error()) 12 | } 13 | } 14 | 15 | func TaskA() error { 16 | var input string 17 | _, err := fmt.Scanln(&input) 18 | if err != nil { 19 | return err 20 | } 21 | 22 | n, err := strconv.Atoi(input) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | var impressiveLine string 28 | charCount := 0 29 | for _ = range n { 30 | _, err := fmt.Scanln(&input) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | set := make(map[rune]struct{}, len(input)) 36 | for _, ch := range input { 37 | set[ch] = struct{}{} 38 | } 39 | 40 | if len(set) > charCount { 41 | charCount = len(set) 42 | impressiveLine = input 43 | } 44 | } 45 | 46 | fmt.Printf("%d %s\n", charCount, impressiveLine) 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /internship_cs_nov21/jury_solutions/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | static class Program 8 | { 9 | static void Main() 10 | { 11 | Console.ReadLine(); 12 | var cycle1 = ReadInts(); 13 | var cycle2 = ReadInts(); 14 | var road = GetRoads(cycle1) 15 | .Intersect(GetRoads(cycle2)) 16 | .First(); 17 | Console.WriteLine(road.Item1 + " " + road.Item2); 18 | } 19 | 20 | private static IEnumerable<(int, int)> GetRoads(int[] cycle) 21 | { 22 | return Enumerable.Range(0, cycle.Length) 23 | .Select(i => 24 | ( 25 | Math.Min(cycle[i], cycle[(i + 1) % cycle.Length]), 26 | Math.Max(cycle[i], cycle[(i + 1) % cycle.Length]) 27 | ) 28 | ); 29 | } 30 | 31 | private static int[] ReadInts() 32 | { 33 | return Console.ReadLine() 34 | .Split() 35 | .Select(int.Parse) 36 | .ToArray(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /hiring_days_cs_nov23/jury_solutions/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public static void Main() 5 | { 6 | var n = int.Parse(Console.ReadLine()); 7 | var numbers = Console.ReadLine().Split().Select(int.Parse).ToArray(); 8 | 9 | var sumLeft = 0; 10 | var sumRight = 0; 11 | var left = 0; 12 | 13 | var right = n - 1; 14 | while (left <= right) 15 | { 16 | if (sumLeft <= sumRight) 17 | { 18 | sumLeft += numbers[left]; 19 | left++; 20 | } 21 | else 22 | { 23 | sumRight += numbers[right]; 24 | right--; 25 | } 26 | } 27 | 28 | if (sumRight == sumLeft) 29 | { 30 | var leftPart = string.Join("+", numbers.Take(left)); 31 | var rightPart = string.Join("+", numbers.Skip(left)); 32 | Console.WriteLine($"{leftPart}={rightPart}"); 33 | } 34 | else 35 | Console.WriteLine(-1); 36 | } -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/cs/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public static void Main() 5 | { 6 | var n = int.Parse(Console.ReadLine()); 7 | var numbers = Console.ReadLine().Split().Select(int.Parse).ToArray(); 8 | 9 | var sumLeft = 0; 10 | var sumRight = 0; 11 | var left = 0; 12 | 13 | var right = n - 1; 14 | while (left <= right) 15 | { 16 | if (sumLeft <= sumRight) 17 | { 18 | sumLeft += numbers[left]; 19 | left++; 20 | } 21 | else 22 | { 23 | sumRight += numbers[right]; 24 | right--; 25 | } 26 | } 27 | 28 | if (sumRight == sumLeft) 29 | { 30 | var leftPart = string.Join("+", numbers.Take(left)); 31 | var rightPart = string.Join("+", numbers.Skip(left)); 32 | Console.WriteLine($"{leftPart}={rightPart}"); 33 | } 34 | else 35 | Console.WriteLine(-1); 36 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/java/A.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.util.stream.Collectors; 3 | 4 | public class A { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | int n = scanner.nextInt(); 9 | 10 | int maxUniqueCount = 0; 11 | var mostImpressiveString = ""; 12 | 13 | for (int i = 0; i < n; i++) { 14 | String currentString = scanner.next(); 15 | 16 | var uniqueChars = currentString.chars() 17 | .mapToObj(ch -> (char) ch) 18 | .collect(Collectors.toCollection(HashSet::new)); 19 | 20 | if (uniqueChars.size() > maxUniqueCount) { 21 | maxUniqueCount = uniqueChars.size(); 22 | mostImpressiveString = currentString; 23 | } 24 | } 25 | 26 | System.out.println(maxUniqueCount + " " + mostImpressiveString); 27 | scanner.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cpp/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | string pattern; 9 | for (char i = 'a'; i <= 'z'; ++i) { 10 | pattern += i; 11 | pattern += toupper(i); 12 | } 13 | int sz = pattern.size(); 14 | map pos; 15 | for (int i = 0; i < sz; ++i) 16 | pos[pattern[i]] = i; 17 | 18 | string s; 19 | cin >> s; 20 | int n = s.length(); 21 | vector t(n); 22 | for (int i = 0; i < n; ++i) 23 | t[i] = pos[s[i]]; 24 | 25 | vector f(n + 1); 26 | int q, l, r, x; 27 | cin >> q; 28 | while(q--) { 29 | cin >> l >> r >> x; 30 | f[l - 1] = (f[l - 1] + x) % sz; 31 | f[r] = ((f[r] - x) % sz + sz) % sz; 32 | } 33 | for (int i = 1; i < n; ++i) 34 | f[i] = (f[i - 1] + f[i]) % sz; 35 | for (int i = 0; i < n; ++i) 36 | cout << pattern[(t[i] + f[i]) % sz]; 37 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cs/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | 6 | namespace ConsoleApp2 7 | { 8 | public class Program 9 | { 10 | private static void Solve() 11 | { 12 | var ints = ReadInts(); 13 | var n = ints[0]; 14 | var possible = new HashSet(); 15 | possible.Add(0); 16 | 17 | for (int i = 0; i < n; i++) 18 | { 19 | var a = ReadInts(); 20 | var newPossible = new HashSet(); 21 | for (int j = 0; j < 6; j++) 22 | foreach (var e in possible) 23 | newPossible.Add(e + a[j]); 24 | 25 | possible = newPossible; 26 | } 27 | 28 | Console.WriteLine(possible.Count); 29 | } 30 | 31 | public static void Main() 32 | { 33 | var T = new Thread(Solve, 10000000); 34 | T.Start(); 35 | } 36 | 37 | private static int[] ReadInts() 38 | { 39 | return Console.ReadLine() 40 | .Split() 41 | .Select(int.Parse) 42 | .ToArray(); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/go/b.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | reader := bufio.NewReader(os.Stdin) 11 | 12 | var count int 13 | fmt.Fscan(reader, &count) 14 | 15 | x := make([]int, count) 16 | y := make([]int, count) 17 | pointsMap := make(map[int]map[int]bool) 18 | 19 | for i := 0; i < count; i++ { 20 | fmt.Fscan(reader, &x[i]) 21 | fmt.Fscan(reader, &y[i]) 22 | if pointsMap[x[i]] == nil { 23 | pointsMap[x[i]] = make(map[int]bool) 24 | } 25 | pointsMap[x[i]][y[i]] = true 26 | } 27 | 28 | max := 0 29 | for i := 0; i < count; i++ { 30 | for j := i + 1; j < count; j++ { 31 | if x[i] == x[j] || y[i] == y[j] { 32 | continue 33 | } 34 | 35 | if pointsMap[x[i]][y[j]] && pointsMap[x[j]][y[i]] { 36 | s := (x[i] - x[j]) * (y[i] - y[j]) 37 | if s < 0 { 38 | s = -s 39 | } 40 | if s > max { 41 | max = s 42 | } 43 | } 44 | } 45 | } 46 | 47 | fmt.Println(max) 48 | } 49 | -------------------------------------------------------------------------------- /cs_schools_oct_23/jury_solutions/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | class Program 5 | { 6 | public static void Main() 7 | { 8 | var n = int.Parse(Console.ReadLine()); 9 | var notes = new (int Left, int Right)[n]; 10 | for (var i = 0; i < n; i++) 11 | { 12 | var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); 13 | notes[i] = (input[0], input[1]); 14 | } 15 | 16 | var sortedNotes = notes.OrderBy(x => x.Left).ToList(); 17 | var currentRight = -1; 18 | var dryTrees = 0L; 19 | for (var i = 0; i < n; i++) 20 | { 21 | if (sortedNotes[i].Left > currentRight) 22 | { 23 | dryTrees += sortedNotes[i].Left - currentRight - 1; 24 | } 25 | 26 | currentRight = Math.Max(currentRight, sortedNotes[i].Right); 27 | } 28 | 29 | var answer = sortedNotes.Select(x => x.Right).Max() + 1 - dryTrees; 30 | Console.WriteLine(answer); 31 | } 32 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/go/c.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | reader := bufio.NewReader(os.Stdin) 11 | 12 | var n, k int 13 | fmt.Fscan(reader, &n) 14 | fmt.Fscan(reader, &k) 15 | 16 | a := make([]int, n) 17 | isZero := make([]int, n) 18 | 19 | for i := 0; i < n; i++ { 20 | fmt.Fscan(reader, &a[i]) 21 | if a[i] == 0 { 22 | isZero[i] = 1 23 | } else { 24 | isZero[i] = 0 25 | } 26 | } 27 | 28 | finish := -1 29 | zeroesCount := 0 30 | sum := 0 31 | ans := 0 32 | for start := 0; start < n; start++ { 33 | for (finish < n-1) && (a[finish+1]+sum <= k) && (isZero[finish+1]+zeroesCount <= 1) { 34 | sum += a[finish+1] 35 | zeroesCount += isZero[finish+1] 36 | finish++ 37 | } 38 | 39 | ans += finish - start + 1 40 | sum -= a[start] 41 | zeroesCount -= isZero[start] 42 | 43 | if finish < start { 44 | sum += a[finish+1] 45 | zeroesCount += isZero[finish+1] 46 | finish++ 47 | } 48 | } 49 | 50 | fmt.Println(ans) 51 | } 52 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/java/TaskA.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TaskA { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt(); 7 | sc.nextLine(); 8 | String[] data = sc.nextLine().split(" "); 9 | printMaxContrastIndexPair(data); 10 | } 11 | private static void printMaxContrastIndexPair(String[] data) { 12 | int min = Integer.MAX_VALUE; 13 | int max = Integer.MIN_VALUE; 14 | int minIndex = -1; 15 | int maxIndex = -1; 16 | int index = 1; 17 | for (String s: data) { 18 | int cur = Integer.parseInt(s); 19 | if (cur >= max) { 20 | max = cur; 21 | maxIndex = index; 22 | } 23 | if (cur < min){ 24 | min = cur; 25 | minIndex = index; 26 | } 27 | index++; 28 | } 29 | System.out.println(String.format("%d %d", maxIndex, minIndex)); 30 | } 31 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cpp/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int size, border, changes; 5 | std::cin >> size >> border >> changes; 6 | 7 | std::vector elements; 8 | 9 | for (int i = 0; i < size; i++) { 10 | int x; 11 | std::cin >> x; 12 | elements.push_back(x); 13 | } 14 | 15 | int left = 0; 16 | int right = 0; 17 | int currentChanges = 0; 18 | int maxLength = 0; 19 | while (right < size) { 20 | if (elements[right] < border) { 21 | right++; 22 | continue; 23 | } 24 | 25 | if (currentChanges < changes) { 26 | currentChanges++; 27 | right++; 28 | continue; 29 | } 30 | 31 | maxLength = std::max(maxLength, right - left); 32 | 33 | while (elements[left] < border) 34 | left++; 35 | 36 | 37 | left++; 38 | right++; 39 | } 40 | 41 | maxLength = std::max(maxLength, right - left); 42 | 43 | std::cout << maxLength; 44 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/java/C.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.stream.Stream; 3 | 4 | public class C { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | int n = scanner.nextInt(); 9 | int k = scanner.nextInt(); 10 | int q = scanner.nextInt(); 11 | 12 | int[] heights = Stream.generate(scanner::nextInt) 13 | .limit(n) 14 | .mapToInt(Integer::intValue) 15 | .toArray(); 16 | 17 | int left = 0, changes = 0, maxLength = 0; 18 | 19 | for (int right = 0; right < n; right++) { 20 | if (heights[right] >= k) { 21 | changes++; 22 | } 23 | 24 | while (changes > q) { 25 | if (heights[left] >= k) { 26 | changes--; 27 | } 28 | left++; 29 | } 30 | 31 | maxLength = Math.max(maxLength, right - left + 1); 32 | } 33 | 34 | System.out.println(maxLength); 35 | scanner.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/cs/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | 5 | public static class Program { 6 | public static void Main() { 7 | var _ = Console.ReadLine(); 8 | var houses = Console.ReadLine().Split().Select(int.Parse).ToArray(); 9 | var heaters = Console.ReadLine().Split().Select(int.Parse).ToArray(); 10 | 11 | var minRadius = new int[houses.Length]; 12 | for (var i = 0; i < minRadius.Length; i++) 13 | minRadius[i] = int.MaxValue; 14 | 15 | var j = 0; 16 | var k = 0; 17 | 18 | Array.Sort(houses); 19 | Array.Sort(heaters); 20 | 21 | while (j < houses.Length ){ 22 | minRadius[j] = Math.Min(minRadius[j], Math.Abs(houses[j] - heaters[k])); 23 | 24 | if (k > 0) 25 | minRadius[j] = Math.Min(minRadius[j], Math.Abs(houses[j] - heaters[k - 1])); 26 | 27 | if (heaters[k] < houses[j] && k < heaters.Length - 1) 28 | k++; 29 | else 30 | j++; 31 | } 32 | 33 | Console.WriteLine(minRadius.Max()); 34 | } 35 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/java/B.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | public class B { 6 | public static void main(String[] args) throws IOException { 7 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 8 | 9 | int n = Integer.parseInt(reader.readLine().trim()); 10 | long throwsX = 0, throwsY = 0; 11 | 12 | for (int i = 0; i < n; i++) { 13 | String[] line = reader.readLine().trim().split(" "); 14 | long x = Long.parseLong(line[0]); 15 | long y = Long.parseLong(line[1]); 16 | throwsX -= x; 17 | throwsY -= y; 18 | } 19 | 20 | for (int i = 0; i < n; i++) { 21 | String[] line = reader.readLine().trim().split(" "); 22 | long x = Long.parseLong(line[0]); 23 | long y = Long.parseLong(line[1]); 24 | throwsX += x; 25 | throwsY += y; 26 | } 27 | 28 | long u = throwsX / n; 29 | long v = throwsY / n; 30 | 31 | System.out.println(u + " " + v); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/java/TaskD.java: -------------------------------------------------------------------------------- 1 | import java.util.HashSet; 2 | import java.util.Scanner; 3 | import java.util.Set; 4 | 5 | public class TaskD { 6 | private static HashSet step = new HashSet<>(); 7 | private static HashSet nextStep = new HashSet<>(); 8 | private static HashSet temp; 9 | 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | sc.nextLine(); 14 | for (int i = 0; i < 6; i++) { 15 | nextStep.add(sc.nextInt()); 16 | } 17 | sc.nextLine(); 18 | for (int i = 1; i < n; i++) { 19 | temp = step; 20 | step = nextStep; 21 | nextStep = temp; 22 | nextStep.clear(); 23 | for (int j = 0; j < 6; j++) { 24 | int number = sc.nextInt(); 25 | for (int cur: step) { 26 | nextStep.add(cur + number); 27 | } 28 | } 29 | sc.nextLine(); 30 | } 31 | System.out.println(nextStep.size()); 32 | } 33 | } -------------------------------------------------------------------------------- /cs_schools_sep24/jury_solutions/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class Solution 4 | { 5 | static void Main() 6 | { 7 | new Solution().Run(); 8 | } 9 | 10 | void Run() 11 | { 12 | var s = Console.ReadLine(); 13 | var t = Console.ReadLine(); 14 | int n = s.Length; 15 | if (s == t) 16 | { 17 | for (int i = 1; i < n; i++) 18 | if (s[i] == s[i - 1]) 19 | { 20 | Console.WriteLine("YES"); 21 | return; 22 | } 23 | Console.WriteLine("NO"); 24 | return; 25 | } 26 | 27 | int l = 0; 28 | while (s[l] == t[l]) 29 | l++; 30 | 31 | int r = n - 1; 32 | while (s[r] == t[r]) 33 | r--; 34 | 35 | if ((s.Substring(l, r - l) == t.Substring(l + 1, r - l) && s[r] == t[l]) 36 | || (s.Substring(l + 1, r - l) == t.Substring(l, r - l) && s[l] == t[r]) 37 | ) 38 | Console.WriteLine("YES"); 39 | else 40 | Console.WriteLine("NO"); 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/python/e.py: -------------------------------------------------------------------------------- 1 | n, m = map(int, input().split()) 2 | f = [[0] * (m + 2) for _ in range(n + 2)] 3 | for i in range(1, n + 1): 4 | f[i][1:m+1] = list(map(int, input())) 5 | ul = [[0] * (m + 2) for _ in range(n + 2)] 6 | ur = [[0] * (m + 2) for _ in range(n + 2)] 7 | dl = [[0] * (m + 2) for _ in range(n + 2)] 8 | dr = [[0] * (m + 2) for _ in range(n + 2)] 9 | 10 | for i in range(1, n + 1): 11 | for j in range(1, m + 1): 12 | ul[i][j] = max(f[i][j], ul[i - 1][j], ul[i][j - 1]) 13 | for i in range(1, n + 1): 14 | for j in range(m, 0, -1): 15 | ur[i][j] = max(f[i][j], ur[i - 1][j], ur[i][j + 1]) 16 | for i in range(n, 0, -1): 17 | for j in range(1, m + 1): 18 | dl[i][j] = max(f[i][j], dl[i + 1][j], dl[i][j - 1]) 19 | for i in range(n, 0, -1): 20 | for j in range(m, 0, -1): 21 | dr[i][j] = max(f[i][j], dr[i + 1][j], dr[i][j + 1]) 22 | ans = 10**9 23 | for i in range(1, n + 1): 24 | for j in range(1, m + 1): 25 | cur_max = max(ul[i - 1][j - 1], ur[i - 1][j + 1], dl[i + 1][j - 1], dr[i + 1][j + 1]) 26 | if ans > cur_max: 27 | ans = cur_max 28 | ans_x, ans_y = i, j 29 | print(ans_x, ans_y) -------------------------------------------------------------------------------- /cs_schools_sep22/jury_solutions/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace ConsoleApp 5 | { 6 | class Program 7 | { 8 | public static void Main() 9 | { 10 | var ints = Console.ReadLine() 11 | .Split() 12 | .Select(int.Parse) 13 | .ToArray(); 14 | int n = ints[0]; 15 | int m = ints[1]; 16 | var map = new string[n]; 17 | for (int i = 0; i < n; i++) 18 | map[i] = Console.ReadLine(); 19 | 20 | var maxPrefix = new int[n + 1][]; 21 | for (int i = 0; i <= n; i++) 22 | maxPrefix[i] = new int[m + 1]; 23 | 24 | for (int i = 1; i < n; i++) 25 | for (int j = 1; j < m; j++) 26 | { 27 | if (map[i][j] == '*') 28 | maxPrefix[i][j] = 0; 29 | else 30 | maxPrefix[i][j] = maxPrefix[i][j - 1] + 1; 31 | } 32 | 33 | int max = 0; 34 | for (int i = 1; i + 1 < n; i++) 35 | for (int j = 1; j + 1 < m; j++) 36 | if (map[i][j] == '.') 37 | { 38 | int width = n * m; 39 | for (int h = i; h > 0; h--) 40 | { 41 | width = Math.Min(maxPrefix[h][j], width); 42 | if (width * (i - h + 1) > max) 43 | max = width * (i - h + 1); 44 | } 45 | } 46 | 47 | Console.WriteLine(max); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/cpp/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n, m; 8 | cin >> n >> m; 9 | vector>> f(n, vector>(m)); 10 | vector> rows(n), cols(m); 11 | 12 | int q, x, y, c; 13 | cin >> q; 14 | for(int t = 0; t < q; ++t) { 15 | cin >> x >> y >> c; --x, --y; 16 | rows[x] = {c, t}; 17 | cols[y] = {c, t}; 18 | } 19 | 20 | for(int i = 0; i < n; ++i) { 21 | if(rows[i].first) { 22 | for(int j = 0; j < m; ++j) { 23 | f[i][j] = rows[i]; 24 | } 25 | } 26 | } 27 | for(int j = 0; j < m; ++j) { 28 | if(cols[j].first) { 29 | for(int i = 0; i < n; ++i) { 30 | if(!f[i][j].first || f[i][j].second < cols[j].second) { 31 | f[i][j] = cols[j]; 32 | } 33 | } 34 | } 35 | } 36 | for(int i = 0; i < n; ++i) { 37 | for(int j = 0; j < m; ++j) { 38 | cout << f[i][j].first << ' '; 39 | } cout << '\n'; 40 | } 41 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/java/B.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class B { 5 | public static void main(String[] args) throws Exception { 6 | new B().run(); 7 | } 8 | 9 | public void run() { 10 | Scanner scanner = new Scanner(System.in); 11 | scanner.nextLine(); 12 | int[] houses = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 13 | int[] heaters = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 14 | 15 | int[] minRadius = new int[houses.length]; 16 | Arrays.fill(minRadius, Integer.MAX_VALUE); 17 | 18 | int j = 0; 19 | int k = 0; 20 | 21 | Arrays.sort(houses); 22 | Arrays.sort(heaters); 23 | 24 | while (j < houses.length) { 25 | minRadius[j] = Math.min(minRadius[j], Math.abs(houses[j] - heaters[k])); 26 | 27 | if (k > 0) 28 | minRadius[j] = Math.min(minRadius[j], Math.abs(houses[j] - heaters[k - 1])); 29 | 30 | if (heaters[k] < houses[j] && k < heaters.length - 1) 31 | k++; 32 | else 33 | j++; 34 | } 35 | 36 | System.out.println(Arrays.stream(minRadius).max().getAsInt()); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/python/c.py: -------------------------------------------------------------------------------- 1 | n, q = map(int, input().split()) 2 | rows, cols = [0] * (n + 2), [0] * (n + 2) 3 | rows[0] = cols[0] = rows[-1] = cols[-1] = 1 4 | v, h = 2, 2 5 | for _ in range(q): 6 | typ, x, y = input().split() 7 | x, y = int(x), int(y) 8 | if typ == '+': 9 | if not rows[x]: 10 | if rows[x - 1] and rows[x + 1]: 11 | h -= 1 12 | elif not rows[x - 1] and not rows[x + 1]: 13 | h += 1 14 | if not cols[y]: 15 | if cols[y - 1] and cols[y + 1]: 16 | v -= 1 17 | elif not cols[y - 1] and not cols[y + 1]: 18 | v += 1 19 | rows[x] += 1 20 | cols[y] += 1 21 | else: 22 | rows[x] -= 1 23 | cols[y] -= 1 24 | if not rows[x]: 25 | if rows[x - 1] and rows[x + 1]: 26 | h += 1 27 | elif not rows[x - 1] and not rows[x + 1]: 28 | h -= 1 29 | if not cols[y]: 30 | if cols[y - 1] and cols[y + 1]: 31 | v += 1 32 | elif not cols[y - 1] and not cols[y + 1]: 33 | v -= 1 34 | print((h - 1) * (v - 1)) 35 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/cpp/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main () 10 | { 11 | string temp; 12 | getline(cin, temp); 13 | vector houses; 14 | vector heaters; 15 | 16 | int n; 17 | while (cin >> n) 18 | { 19 | houses.push_back(n); 20 | if (cin.peek() == '\n') 21 | break; 22 | } 23 | while (cin >> n) 24 | { 25 | heaters.push_back(n); 26 | if (cin.peek() == '\n') 27 | break; 28 | } 29 | 30 | vector min_radius(houses.size(), numeric_limits::max()); 31 | 32 | int j = 0; 33 | int k = 0; 34 | 35 | sort(houses.begin(), houses.end()); 36 | sort(heaters.begin(), heaters.end()); 37 | 38 | while (j < houses.size()) 39 | { 40 | min_radius[j] = min(min_radius[j], abs(houses[j] - heaters[k])); 41 | 42 | if (k > 0) 43 | min_radius[j] = min(min_radius[j], abs(houses[j] - heaters[k - 1])); 44 | 45 | if (heaters[k] < houses[j] && k < heaters.size() - 1) 46 | k++; 47 | else 48 | j++; 49 | } 50 | 51 | cout << *max_element(min_radius.begin(), min_radius.end()) << endl; 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /cs_schools_sep24/jury_solutions/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | public class Solution 6 | { 7 | static void Main() 8 | { 9 | new Solution().Run(); 10 | } 11 | 12 | void Run() 13 | { 14 | int n = int.Parse(Console.ReadLine()); 15 | var weights = ReadLongs(); 16 | long sum = weights.Sum(); 17 | if (sum % 2 == 1) 18 | { 19 | Console.WriteLine("0 0"); 20 | return; 21 | } 22 | 23 | long currentSum = 0; 24 | var prefixSums = new Dictionary(); 25 | prefixSums[0] = -1; 26 | for (int i = 0; i < n; ++i) 27 | { 28 | currentSum += weights[i]; 29 | prefixSums[currentSum] = i; 30 | if (currentSum >= sum / 2 && prefixSums.ContainsKey(currentSum - sum / 2)) 31 | { 32 | Console.WriteLine($"{prefixSums[currentSum - sum / 2] + 2} {i + 1}"); 33 | return; 34 | } 35 | } 36 | Console.WriteLine("0 0"); 37 | } 38 | 39 | long[] ReadLongs() 40 | { 41 | return Console.ReadLine().Split().Select(long.Parse).ToArray(); 42 | } 43 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/java/TaskC.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TaskC { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt(); 7 | int k = sc.nextInt(); 8 | sc.nextLine(); 9 | int[] data = new int[n]; 10 | for (int i = 0; i < n; i++) { 11 | data[i] = sc.nextInt(); 12 | } 13 | long result = 0; 14 | int stopIndex = 0; 15 | int sum = 0; 16 | boolean hasZero = false; 17 | for (int i = 0; i < n; i++) { 18 | while (stopIndex < n && (data[stopIndex] != 0 || !hasZero)) { 19 | if (data[stopIndex] == 0) hasZero = true; 20 | sum += data[stopIndex]; 21 | if (sum <= k) { 22 | stopIndex++; 23 | } 24 | else 25 | { 26 | sum -= data[stopIndex]; 27 | break; 28 | } 29 | } 30 | result += stopIndex - i; 31 | sum -= data[i]; 32 | if (data[i] == 0) hasZero = false; 33 | } 34 | System.out.println(result); 35 | } 36 | } -------------------------------------------------------------------------------- /internship_cs_nov21/jury_solutions/e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace ConsoleApp 5 | { 6 | static class Program 7 | { 8 | static void Main() 9 | { 10 | var longs = ReadLongArray(); 11 | var ySize = longs[0]; 12 | var xSize = longs[1]; 13 | var yLines = ReadLongArray(); 14 | var xLines = ReadLongArray(); 15 | 16 | var grayRows = CountGrayLines(yLines); 17 | var grayColumns = CountGrayLines(xLines); 18 | 19 | var black = 20 | ySize * xLines.Length 21 | + xSize * yLines.Length 22 | - xLines.Length * yLines.Length; 23 | var gray = 24 | (ySize - yLines.Length) * grayColumns 25 | + (xSize - xLines.Length) * grayRows 26 | - grayColumns * grayRows; 27 | var white = ySize * xSize - black - gray; 28 | Console.WriteLine($"{gray} {white} {black}"); 29 | } 30 | 31 | private static long CountGrayLines(long[] coords) 32 | { 33 | long grayLines = 2 * coords.Length - 2; 34 | for (int i = 0; i < coords.Length - 1; i++) 35 | if (coords[i + 1] - coords[i] == 2) 36 | grayLines--; 37 | return grayLines; 38 | } 39 | 40 | private static long[] ReadLongArray() 41 | { 42 | return Console.ReadLine() 43 | .Split() 44 | .Select(long.Parse) 45 | .ToArray(); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /hiring_days_cs_nov21/jury_solutions/c_slow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | class Program 8 | { 9 | static void Main() 10 | { 11 | var minGoodMood = ReadIntegers().ToList()[1]; 12 | var moods = new Queue 13 | ( 14 | ReadIntegers().Select(a => a < minGoodMood ? 0 : 1) 15 | ); 16 | 17 | int m = int.Parse(Console.ReadLine()); 18 | 19 | for (int i = 0; i < m; i++) 20 | { 21 | var integers = ReadIntegers().ToList(); 22 | var queryType = integers[0]; 23 | 24 | switch (queryType) 25 | { 26 | case 1: 27 | { 28 | var mood = integers[1] < minGoodMood ? 0 : 1; 29 | moods.Enqueue(mood); 30 | break; 31 | } 32 | case 2: 33 | { 34 | moods.Dequeue(); 35 | break; 36 | } 37 | case 3: 38 | { 39 | var indexFromQueueStart = integers[1]; 40 | var result = moods 41 | .Take(indexFromQueueStart) 42 | .Sum(); 43 | Console.WriteLine(result); 44 | break; 45 | } 46 | } 47 | } 48 | } 49 | 50 | private static IEnumerable ReadIntegers() 51 | { 52 | return Console.ReadLine() 53 | .Split() 54 | .Select(int.Parse); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cpp/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | long long maxX, maxY, xCount, yCount; 5 | std::cin >> maxX >> maxY >> xCount >> yCount; 6 | 7 | std::set xLines; 8 | std::set yLines; 9 | for (int i = 0; i < xCount; i++) { 10 | long long border; 11 | std::cin >> border; 12 | xLines.insert(border); 13 | } 14 | 15 | for (int i = 0; i < yCount; i++) { 16 | long long border; 17 | std::cin >> border; 18 | yLines.insert(border); 19 | } 20 | 21 | xLines.insert(0); 22 | yLines.insert(0); 23 | 24 | xLines.insert(maxX); 25 | yLines.insert(maxY); 26 | 27 | int queriesCount; 28 | std::cin >> queriesCount; 29 | 30 | while (queriesCount--) { 31 | long long x1, y1, x2, y2; 32 | std::cin >> x1 >> y1 >> x2 >> y2; 33 | 34 | auto rangX1 = xLines.lower_bound(x1); 35 | auto rangX2 = xLines.lower_bound(x2); 36 | 37 | auto rangY1 = yLines.lower_bound(y1); 38 | auto rangY2 = yLines.lower_bound(y2); 39 | 40 | if (rangX1 == rangX2 && rangY1 == rangY2) 41 | std::cout << "YES\n"; 42 | else 43 | std::cout << "NO\n"; 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cs/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | 6 | namespace ConsoleApp2 7 | { 8 | public class Program 9 | { 10 | private static void Solve() 11 | { 12 | int n = int.Parse(Console.ReadLine()); 13 | var x = new int[n]; 14 | var y = new int[n]; 15 | var points = new HashSet<(int, int)>(); 16 | for (int i = 0; i < n; i++) 17 | { 18 | var ints = ReadInts(); 19 | x[i] = ints[0]; 20 | y[i] = ints[1]; 21 | points.Add((x[i], y[i])); 22 | } 23 | 24 | long max = 0; 25 | for (int i = 0; i < n; i++) 26 | for (int j = i + 1; j < n; j++) 27 | { 28 | if (x[i] == x[j] || y[i] == y[j]) 29 | continue; 30 | if (points.Contains((x[i], y[j])) && points.Contains((x[j], y[i]))) 31 | { 32 | var s = (long) Math.Abs(x[i] - x[j]) * Math.Abs(y[i] - y[j]); 33 | if (s > max) 34 | max = s; 35 | } 36 | } 37 | 38 | Console.WriteLine(max); 39 | } 40 | 41 | 42 | public static void Main() 43 | { 44 | var T = new Thread(Solve, 10000000); 45 | T.Start(); 46 | } 47 | 48 | private static int[] ReadInts() 49 | { 50 | return Console.ReadLine() 51 | .Split() 52 | .Select(int.Parse) 53 | .ToArray(); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cpp/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | signed main() { 9 | int n, m; 10 | cin >> n >> m; 11 | vector> f(n + 2, vector(m + 2)); 12 | char t; 13 | for (int i = 1; i <= n; ++i) 14 | for (int j = 1; j <= m; ++j) 15 | cin >> t, f[i][j] = t - '0'; 16 | auto ul = f; auto ur = f; 17 | auto dl = f; auto dr = f; 18 | for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) 19 | ul[i][j] = max(ul[i][j], max(ul[i - 1][j], ul[i][j - 1])); 20 | for (int i = 1; i <= n; ++i) for (int j = m; j >= 1; --j) 21 | ur[i][j] = max(ur[i][j], max(ur[i - 1][j], ur[i][j + 1])); 22 | for (int i = n; i >= 1; --i) for (int j = 1; j <= m; ++j) 23 | dl[i][j] = max(dl[i][j], max(dl[i + 1][j], dl[i][j - 1])); 24 | for (int i = n; i >= 1; --i) for (int j = m; j >= 1; --j) 25 | dr[i][j] = max(dr[i][j], max(dr[i + 1][j], dr[i][j + 1])); 26 | int ans = 1e9, ans_x = -1, ans_y = -1; 27 | for (int i = 1; i <= n; ++i) 28 | for (int j = 1; j <= m; ++j){ 29 | int cur_max = max( 30 | max(ul[i - 1][j - 1], ur[i - 1][j + 1]), 31 | max(dl[i + 1][j - 1], dr[i + 1][j + 1]) 32 | ); 33 | if(ans > cur_max){ 34 | ans = cur_max; 35 | ans_x = i, ans_y = j; 36 | } 37 | } 38 | cout << ans_x << ' ' << ans_y << '\n'; 39 | } 40 | -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cs/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | 5 | class Program 6 | { 7 | static void Main() 8 | { 9 | Solve(); 10 | } 11 | 12 | static void Solve() 13 | { 14 | var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); 15 | var size = input[0]; 16 | var border = input[1]; 17 | var changes = input[2]; 18 | var elements = Console.ReadLine().Split().Select(int.Parse).ToArray(); 19 | var left = 0; 20 | var right = 0; 21 | var currentChanges = 0; 22 | var maxLength = 0; 23 | while (right < size) 24 | { 25 | if (elements[right] < border) 26 | { 27 | right++; 28 | continue; 29 | } 30 | 31 | if (currentChanges < changes) 32 | { 33 | currentChanges++; 34 | right++; 35 | continue; 36 | } 37 | 38 | maxLength = Math.Max(maxLength, right - left); 39 | 40 | while (elements[left] < border) 41 | left++; 42 | 43 | 44 | left++; 45 | right++; 46 | } 47 | 48 | maxLength = Math.Max(maxLength, right - left); 49 | 50 | Console.WriteLine(maxLength); 51 | } 52 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cs/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading; 4 | 5 | namespace ConsoleApp2 6 | { 7 | public class Program 8 | { 9 | private static void Solve() 10 | { 11 | var ints = ReadInts(); 12 | var n = ints[0]; 13 | var k = (long) ints[1]; 14 | var a = ReadInts(); 15 | var isZero = a.Select(e => e == 0 ? 1 : 0).ToArray(); 16 | 17 | int finish = -1; 18 | int zeroesCount = 0; 19 | long sum = 0; 20 | long ans = 0; 21 | for (int start = 0; start < n; start++) 22 | { 23 | while (finish < n - 1 && a[finish + 1] + sum <= k && isZero[finish + 1] + zeroesCount <= 1) 24 | { 25 | sum += a[finish + 1]; 26 | zeroesCount += isZero[finish + 1]; 27 | finish++; 28 | } 29 | 30 | ans += finish - start + 1; 31 | sum -= a[start]; 32 | zeroesCount -= isZero[start]; 33 | 34 | if (finish < start) 35 | { 36 | sum += a[finish + 1]; 37 | zeroesCount += isZero[finish + 1]; 38 | finish++; 39 | } 40 | } 41 | 42 | Console.WriteLine(ans); 43 | } 44 | 45 | 46 | public static void Main() 47 | { 48 | var T = new Thread(Solve, 10000000); 49 | T.Start(); 50 | } 51 | 52 | private static int[] ReadInts() 53 | { 54 | return Console.ReadLine() 55 | .Split() 56 | .Select(int.Parse) 57 | .ToArray(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /cs_schools_sep22/jury_solutions/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | class Program 8 | { 9 | public static void Main() 10 | { 11 | int n = int.Parse(Console.ReadLine()); 12 | var table = new List<(string, int)>(); 13 | for (int i = 0; i < n; i++) 14 | { 15 | var tokens = Console.ReadLine().Split(); 16 | table.Add((tokens[0], int.Parse(tokens[1]))); 17 | } 18 | 19 | var teams = Console.ReadLine().Split('-'); 20 | 21 | int res1 = Solve(table.ToArray(), teams[0], 3, teams[1], 0); 22 | int res2 = Solve(table.ToArray(), teams[0], 1, teams[1], 1); 23 | int res3 = Solve(table.ToArray(), teams[0], 0, teams[1], 3); 24 | Console.WriteLine(res1 + " " + res2 + " " + res3); 25 | } 26 | 27 | private static int Solve((string, int)[] table, string team1, int p1, string team2, int p2) 28 | { 29 | int index1 = Enumerable.Range(0, table.Length).First(i => table[i].Item1 == team1); 30 | table[index1] = (table[index1].Item1, table[index1].Item2 + p1); 31 | 32 | int index2 = Enumerable.Range(0, table.Length).First(i => table[i].Item1 == team2); 33 | table[index2] = (table[index2].Item1, table[index2].Item2 + p2); 34 | 35 | table = table.OrderByDescending(item => item.Item2).ThenBy(item => item.Item1).ToArray(); 36 | return Enumerable.Range(0, table.Length).First(i => table[i].Item1 == team1) + 1; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /internship_cs_feb22/jury_solutions/b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | static class Program 8 | { 9 | static void Main() 10 | { 11 | var k = int.Parse(Console.ReadLine()); 12 | var s = Console.ReadLine(); 13 | var t = Console.ReadLine(); 14 | 15 | var sCounts = Enumerable.Range(0, 26).ToDictionary(i => (char) ('a' + i), i => 0); 16 | var tCounts = Enumerable.Range(0, 26).ToDictionary(i => (char) ('a' + i), i => 0); 17 | 18 | foreach (var c in t) 19 | tCounts[c]++; 20 | 21 | for (int i = 0; i < k; i++) 22 | sCounts[s[i]]++; 23 | 24 | if (Check(sCounts, tCounts)) 25 | { 26 | Console.WriteLine("YES"); 27 | Console.WriteLine(s.Substring(0, k)); 28 | return; 29 | } 30 | 31 | for (int i = k; i < s.Length; i++) 32 | { 33 | sCounts[s[i - k]]--; 34 | sCounts[s[i]]++; 35 | if (Check(sCounts, tCounts)) 36 | { 37 | Console.WriteLine("YES"); 38 | Console.WriteLine(s.Substring(i - k + 1, k)); 39 | return; 40 | } 41 | } 42 | 43 | Console.WriteLine("NO"); 44 | } 45 | 46 | private static bool Check(Dictionary sCounts, Dictionary tCounts) 47 | { 48 | foreach (var kvp in sCounts) 49 | { 50 | if (!tCounts.ContainsKey(kvp.Key) || tCounts[kvp.Key] < kvp.Value) 51 | return false; 52 | } 53 | 54 | return true; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/java/TaskA.java: -------------------------------------------------------------------------------- 1 | import java.io.ByteArrayInputStream; 2 | import java.io.InputStream; 3 | import java.nio.charset.StandardCharsets; 4 | import java.util.Scanner; 5 | 6 | public class TaskA { 7 | 8 | public String testIfGivenRollsNumberSufficient() { 9 | return testIfGivenRollsNumberSufficient(System.in); 10 | } 11 | 12 | String testIfGivenRollsNumberSufficient(String input) { 13 | return testIfGivenRollsNumberSufficient(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8))); 14 | } 15 | 16 | private String testIfGivenRollsNumberSufficient(InputStream inputStream) { 17 | try (Scanner scanner = new Scanner(inputStream)) { 18 | int n = scanner.nextInt(); 19 | long t = scanner.nextLong(); 20 | 21 | long aNumbersSum = 0; 22 | for (int i = 0; i < n; i++) { 23 | aNumbersSum += scanner.nextInt(); 24 | } 25 | 26 | long bNumbersSum = 0; 27 | for (int i = 0; i < n; i++) { 28 | bNumbersSum += scanner.nextInt(); 29 | } 30 | 31 | return t >= aNumbersSum && t <= bNumbersSum ? "YES" : "NO"; 32 | } 33 | } 34 | 35 | public static void main(String[] args) { 36 | String result = new TaskA().testIfGivenRollsNumberSufficient(); 37 | System.out.print(result); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/go/c.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | func main() { 9 | err := TaskC() 10 | if err != nil { 11 | fmt.Printf("err: %s\n", err.Error()) 12 | } 13 | } 14 | 15 | func TaskC() error { 16 | n := ReadInt() 17 | k := ReadInt() 18 | q := ReadInt() 19 | 20 | array, count := readArray(n, k) 21 | 22 | if q >= len(array) { 23 | fmt.Printf("%d\n", n) 24 | return nil 25 | } 26 | 27 | array = append(array, count+1) 28 | 29 | sumBuildings := 0 30 | for i := range q { 31 | sumBuildings += array[i] 32 | } 33 | 34 | maxSum := math.MinInt 35 | for i := q; i < len(array); i++ { 36 | sumBuildings += array[i] - 1 37 | 38 | if sumBuildings > maxSum { 39 | maxSum = sumBuildings 40 | } 41 | sumBuildings -= array[i-q] 42 | sumBuildings += 1 43 | } 44 | 45 | fmt.Printf("%d\n", maxSum) 46 | 47 | return nil 48 | } 49 | 50 | func readArray(n, k int) ([]int, int) { 51 | array := make([]int, 0, n) 52 | count := 0 53 | 54 | for _ = range n { 55 | h := ReadInt() 56 | 57 | count += 1 58 | 59 | if h >= k { 60 | array = append(array, count) 61 | count = 0 62 | } 63 | } 64 | 65 | return array, count 66 | } 67 | 68 | func ReadInt() int { 69 | var input string 70 | fmt.Scan(&input) 71 | return toInt(input) 72 | } 73 | 74 | func toInt(buf string) int { 75 | n := 0 76 | for _, v := range buf { 77 | n = n*10 + int(v-'0') 78 | } 79 | return n 80 | } 81 | -------------------------------------------------------------------------------- /hiring_days_cs_nov23/jury_solutions/e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | var ints = ReadInts(); 10 | int n = ints[0]; 11 | int m = ints[1]; 12 | int t = int.Parse(Console.ReadLine()); 13 | 14 | var colorsH = new (int, int)[n]; 15 | var colorsV = new (int, int)[m]; 16 | 17 | for (int i = 1; i <= t; i++) 18 | { 19 | var line = ReadInts(); 20 | int x = line[0] - 1; 21 | int y = line[1] - 1; 22 | int c = line[2]; 23 | colorsH[x] = (c, i); 24 | colorsV[y] = (c, i); 25 | } 26 | 27 | var result = new StringBuilder(); 28 | for (int i = 0; i < n; i++) 29 | { 30 | for (int j = 0; j < m; j++) 31 | { 32 | var ans1 = colorsH[i]; 33 | var ans2 = colorsV[j]; 34 | result.Append(ans1.Item2 > ans2.Item2 ? ans1.Item1 : ans2.Item1); 35 | result.Append(' '); 36 | } 37 | 38 | result.AppendLine(); 39 | } 40 | 41 | Console.Write(result); 42 | } 43 | 44 | private static int[] ReadInts() 45 | { 46 | return Console.ReadLine() 47 | .Split() 48 | .Select(int.Parse) 49 | .ToArray(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /internship_dec23/jury_solutions/cs/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | var ints = ReadInts(); 10 | int n = ints[0]; 11 | int m = ints[1]; 12 | int t = int.Parse(Console.ReadLine()); 13 | 14 | var colorsH = new (int, int)[n]; 15 | var colorsV = new (int, int)[m]; 16 | 17 | for (int i = 1; i <= t; i++) 18 | { 19 | var line = ReadInts(); 20 | int x = line[0] - 1; 21 | int y = line[1] - 1; 22 | int c = line[2]; 23 | colorsH[x] = (c, i); 24 | colorsV[y] = (c, i); 25 | } 26 | 27 | var result = new StringBuilder(); 28 | for (int i = 0; i < n; i++) 29 | { 30 | for (int j = 0; j < m; j++) 31 | { 32 | var ans1 = colorsH[i]; 33 | var ans2 = colorsV[j]; 34 | result.Append(ans1.Item2 > ans2.Item2 ? ans1.Item1 : ans2.Item1); 35 | result.Append(' '); 36 | } 37 | 38 | result.AppendLine(); 39 | } 40 | 41 | Console.Write(result); 42 | } 43 | 44 | private static int[] ReadInts() 45 | { 46 | return Console.ReadLine() 47 | .Split() 48 | .Select(int.Parse) 49 | .ToArray(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/go/b.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "math" 7 | "os" 8 | "slices" 9 | ) 10 | 11 | func main() { 12 | err := TaskB() 13 | if err != nil { 14 | fmt.Printf("err: %s\n", err.Error()) 15 | } 16 | } 17 | 18 | func TaskB() error { 19 | scanner := bufio.NewScanner(os.Stdin) 20 | 21 | var n int 22 | 23 | scanner.Scan() 24 | fmt.Sscanf(scanner.Text(), "%d", &n) 25 | 26 | firstX, firstY, err := ReadPointsFindMin(scanner, n) 27 | if err != nil { 28 | return err 29 | } 30 | 31 | secondX, secondY, err := ReadPointsFindMin(scanner, n) 32 | if err != nil { 33 | return err 34 | } 35 | 36 | fmt.Printf("%d %d\n", secondX-firstX, secondY-firstY) 37 | 38 | return nil 39 | } 40 | 41 | func ReadPointsFindMin(scanner *bufio.Scanner, n int) (int, int, error) { 42 | minX := math.MaxInt 43 | minY := math.MaxInt 44 | for _ = range n { 45 | scanner.Scan() 46 | 47 | bytes := scanner.Bytes() 48 | idx := slices.Index[[]byte](bytes, byte(' ')) 49 | 50 | x := toInt(bytes[:idx]) 51 | y := toInt(bytes[idx+1:]) 52 | 53 | if x < minX { 54 | minX = x 55 | minY = y 56 | } else if x == minX && y < minY { 57 | minY = y 58 | } 59 | } 60 | 61 | return minX, minY, nil 62 | } 63 | 64 | func toInt(buf []byte) int { 65 | n := 0 66 | sign := 1 67 | if buf[0] == byte('-') { 68 | buf = buf[1:] 69 | sign = -1 70 | } 71 | for _, v := range buf { 72 | n = n*10 + int(v-'0') 73 | } 74 | return n * sign 75 | } 76 | -------------------------------------------------------------------------------- /hiring_days_cs_nov21/jury_solutions/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | class Program 8 | { 9 | static void Main() 10 | { 11 | var minGoodMood = ReadIntegers().ToList()[1]; 12 | var moods = ReadIntegers() 13 | .Select(a => a < minGoodMood ? 0 : 1) 14 | .ToList(); 15 | var prefixSums = new List {0}; 16 | for (int i = 0; i < moods.Count; i++) 17 | prefixSums.Add(prefixSums[i] + moods[i]); 18 | 19 | int m = int.Parse(Console.ReadLine()); 20 | int queueStart = 0; 21 | 22 | for (int i = 0; i < m; i++) 23 | { 24 | var integers = ReadIntegers().ToList(); 25 | var queryType = integers[0]; 26 | 27 | switch (queryType) 28 | { 29 | case 1: 30 | { 31 | var mood = integers[1] < minGoodMood ? 0 : 1; 32 | moods.Add(mood); 33 | prefixSums.Add(prefixSums[prefixSums.Count - 1] + mood); 34 | break; 35 | } 36 | case 2: 37 | { 38 | queueStart++; 39 | break; 40 | } 41 | case 3: 42 | { 43 | var indexFromQueueStart = integers[1]; 44 | Console.WriteLine(prefixSums[indexFromQueueStart + queueStart] - prefixSums[queueStart]); 45 | break; 46 | } 47 | } 48 | } 49 | } 50 | 51 | private static IEnumerable ReadIntegers() 52 | { 53 | return Console.ReadLine() 54 | .Split() 55 | .Select(int.Parse); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/go/b.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "sort" 8 | ) 9 | 10 | func main() { 11 | reader := bufio.NewReader(os.Stdin) 12 | 13 | var houses []int 14 | var heaters []int 15 | 16 | var n, m int 17 | fmt.Fscan(reader, &n) 18 | fmt.Fscan(reader, &m) 19 | houses = make([]int, n) 20 | for i := 0; i < n; i++ { 21 | fmt.Fscan(reader, &houses[i]) 22 | } 23 | 24 | heaters = make([]int, m) 25 | for i := 0; i < m; i++ { 26 | fmt.Fscan(reader, &heaters[i]) 27 | } 28 | 29 | minRadius := make([]int, n) 30 | for i := range minRadius { 31 | minRadius[i] = 1000000000 32 | } 33 | 34 | j, k := 0, 0 35 | 36 | sort.Ints(houses) 37 | sort.Ints(heaters) 38 | 39 | for j < n { 40 | d1 := max(houses[j]-heaters[k], -houses[j]+heaters[k]) 41 | minRadius[j] = min(minRadius[j], d1) 42 | 43 | if k > 0 { 44 | d2 := max(houses[j]-heaters[k-1], -houses[j]+heaters[k-1]) 45 | 46 | minRadius[j] = min(minRadius[j], d2) 47 | } 48 | 49 | if heaters[k] < houses[j] && k < m-1 { 50 | k++ 51 | } else { 52 | j++ 53 | } 54 | } 55 | 56 | maxRadius := minRadius[0] 57 | for _, radius := range minRadius { 58 | if radius > maxRadius { 59 | maxRadius = radius 60 | } 61 | } 62 | 63 | fmt.Println(maxRadius) 64 | } 65 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cs/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Summer2024 5 | { 6 | public class Program 7 | { 8 | public static void Main() 9 | { 10 | var line = Console.ReadLine(); 11 | var queriesCount = int.Parse(Console.ReadLine()); 12 | 13 | var alphabet = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (char)i).SelectMany(c => new[] { c, c.ToString().ToUpper()[0] }).ToArray(); 14 | var alphabetCharToIndex = Enumerable.Range(0, alphabet.Length).ToDictionary(x => alphabet[x]); 15 | 16 | var offsets = new long[line.Length + 1]; 17 | foreach (var _ in Enumerable.Range(0, queriesCount)) 18 | { 19 | var (left, right, value) = ReadQuery(); 20 | offsets[left - 1] += value; 21 | offsets[right] -= value; 22 | } 23 | 24 | foreach (var i in Enumerable.Range(1, line.Length)) 25 | offsets[i] += offsets[i - 1]; 26 | 27 | var result = Enumerable.Range(0, line.Length).Select(i => alphabet[(alphabetCharToIndex[line[i]] + offsets[i]) % alphabet.Length]); 28 | Console.WriteLine(string.Join("", result)); 29 | } 30 | 31 | private static (int left, int right, int value) ReadQuery() 32 | { 33 | var inputValues = Console.ReadLine().Split().Select(int.Parse).ToArray(); 34 | return (inputValues[0], inputValues[1], inputValues[2]); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /cs_schools_sep22/jury_solutions/e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace ConsoleApp 7 | { 8 | class Program 9 | { 10 | public static void Main() 11 | { 12 | int n = int.Parse(Console.ReadLine()); 13 | var builder = new StringBuilder(); 14 | var data = new Dictionary>(); 15 | for (int i = 0; i < n; i++) 16 | { 17 | var s = Console.ReadLine(); 18 | int index = Enumerable.Range(0, s.Length).First(j => char.IsDigit(s[j])); 19 | var name = s.Substring(0, index); 20 | var number = int.Parse(s.Substring(index)); 21 | if (!data.ContainsKey(name)) 22 | data[name] = new List(); 23 | data[name].Add(number); 24 | } 25 | 26 | var dataQueues = data.ToDictionary 27 | ( 28 | kvp => kvp.Key, 29 | kvp => new Queue(kvp.Value.OrderBy(x => x)) 30 | ); 31 | 32 | var firstFree = new Dictionary(); 33 | int q = int.Parse(Console.ReadLine()); 34 | for (int i = 0; i < q; i++) 35 | { 36 | var query = Console.ReadLine(); 37 | var candidate = firstFree.ContainsKey(query) ? firstFree[query] : 1; 38 | 39 | if (dataQueues.ContainsKey(query)) 40 | { 41 | var queue = dataQueues[query]; 42 | while (queue.Count > 0 && queue.Peek() == candidate) 43 | { 44 | candidate++; 45 | queue.Dequeue(); 46 | } 47 | } 48 | 49 | builder.AppendLine(candidate.ToString()); 50 | firstFree[query] = candidate + 1; 51 | } 52 | 53 | Console.Write(builder); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cpp/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define int long long 5 | 6 | using namespace std; 7 | 8 | signed main() { 9 | int n, q, x, y; 10 | cin >> n >> q; 11 | char type; 12 | vector rows(n + 2), cols(n + 2); 13 | rows[0] = rows[n + 1] = cols[0] = cols[n + 1] = 1; 14 | int v = 2, h = 2; 15 | while(q--) { 16 | cin >> type >> x >> y; 17 | if (type == '+') { 18 | if (rows[x] == 0) { 19 | if (rows[x - 1] && rows[x + 1]) 20 | --h; 21 | else if (!rows[x - 1] && !rows[x + 1]) 22 | ++h; 23 | } 24 | if (cols[y] == 0) { 25 | if (cols[y - 1] && cols[y + 1]) 26 | --v; 27 | else if (!cols[y - 1] && !cols[y + 1]) 28 | ++v; 29 | } 30 | ++rows[x], ++cols[y]; 31 | } 32 | else { 33 | --rows[x], --cols[y]; 34 | if (rows[x] == 0) { 35 | if (rows[x - 1] && rows[x + 1]) 36 | ++h; 37 | else if (!rows[x - 1] && !rows[x + 1]) 38 | --h; 39 | } 40 | if (cols[y] == 0) { 41 | if (cols[y - 1] && cols[y + 1]) 42 | ++v; 43 | else if (!cols[y - 1] && !cols[y + 1]) 44 | --v; 45 | } 46 | } 47 | cout << (h - 1) * (v - 1) << '\n'; 48 | } 49 | } -------------------------------------------------------------------------------- /internship_cs_feb22/jury_solutions/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | static class Program 8 | { 9 | public class LongNumber 10 | { 11 | private List digits; 12 | private int shift; 13 | 14 | public LongNumber(string s) 15 | { 16 | shift = 0; 17 | digits = s.Select(c => c - '0').Reverse().ToList(); 18 | } 19 | 20 | public int Length => digits.Count - shift; 21 | public int LastDigit => digits[shift]; 22 | 23 | public static LongNumber operator +(LongNumber a, int x) 24 | { 25 | a.digits[a.shift] += x; 26 | int i = a.shift; 27 | while (a.digits[i] >= 10) 28 | { 29 | if (i == a.digits.Count - 1) 30 | a.digits.Add(a.digits[i] / 10); 31 | else 32 | a.digits[i + 1] += a.digits[i] / 10; 33 | a.digits[i] %= 10; 34 | i++; 35 | } 36 | 37 | return a; 38 | } 39 | 40 | public void DivideByTen() 41 | { 42 | shift++; 43 | } 44 | } 45 | 46 | static void Main() 47 | { 48 | int t = int.Parse(Console.ReadLine()); 49 | for (int i = 0; i < t; i++) 50 | { 51 | var s = Console.ReadLine(); 52 | var number = new LongNumber(s); 53 | var used = new HashSet(); 54 | while (number.Length > 1 || !used.Contains(number.LastDigit)) 55 | { 56 | if (number.Length == 1) 57 | used.Add(number.LastDigit); 58 | int lastDigit = number.LastDigit; 59 | while (number.LastDigit != 0) 60 | number += lastDigit; 61 | number.DivideByTen(); 62 | } 63 | 64 | Console.WriteLine(used.Min()); 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cs/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | 5 | class Program 6 | { 7 | static void Main() 8 | { 9 | Solve(); 10 | } 11 | 12 | public static void Solve() 13 | { 14 | var bounds = Console.ReadLine().Split().Select(long.Parse).ToArray(); 15 | var maxX = bounds[0]; 16 | var maxY = bounds[1]; 17 | 18 | var pointsCount = Console.ReadLine().Split().Select(long.Parse).ToArray(); 19 | var xCount = pointsCount[0]; 20 | var yCount = pointsCount[1]; 21 | 22 | var xLines = Console.ReadLine().Split().Select(long.Parse).ToList(); 23 | var yLines = Console.ReadLine().Split().Select(long.Parse).ToList(); 24 | 25 | var queriesCount = int.Parse(Console.ReadLine()); 26 | 27 | xLines.Add(0); 28 | xLines.Add(maxX); 29 | xLines.Sort(); 30 | 31 | yLines.Add(0); 32 | yLines.Add(maxY); 33 | yLines.Sort(); 34 | 35 | while (queriesCount-- > 0) 36 | { 37 | var query = Console.ReadLine().Split().Select(long.Parse).ToArray(); 38 | var x1 = query[0]; 39 | var y1 = query[1]; 40 | 41 | var x2 = query[2]; 42 | var y2 = query[3]; 43 | 44 | var xRangDiff = xLines.BinarySearch(x1) - xLines.BinarySearch(x2) == 0; 45 | var yRangDiff = yLines.BinarySearch(y1) - yLines.BinarySearch(y2) == 0; 46 | 47 | if (xRangDiff && yRangDiff) 48 | Console.WriteLine("YES"); 49 | else 50 | Console.WriteLine("NO"); 51 | } 52 | 53 | } 54 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/python/e.py: -------------------------------------------------------------------------------- 1 | def isInBounds(x, y, n, m): 2 | return x >= 0 and x < n and y >= 0 and y < m 3 | 4 | def dfs(startX, startY, setNumber, n, m, setsNumbers, field, used, steps): 5 | stack = [] 6 | stack.append((startX, startY)) 7 | used[startX][startY] = setNumber 8 | 9 | while(len(stack) != 0): 10 | (currentX, currentY) = stack[-1] 11 | stack.pop() 12 | setsNumbers[setNumber]+=1 13 | for (stepX, stepY) in steps: 14 | posX = currentX+stepX 15 | posY = currentY+stepY 16 | if isInBounds(posX, posY, n, m) and field[posX][posY] == 'X' and used[posX][posY] == 0: 17 | stack.append((posX, posY)) 18 | used[posX][posY] = setNumber 19 | 20 | 21 | 22 | steps = [ (1, 0), (-1, 0), (0, 1), (0, -1) ] 23 | 24 | n,m,q = map(int, input().split()) 25 | setsNumbers = [0 for i in range(n * m)] 26 | field = [ [0 for i in range(m)] for i in range(n)] 27 | used = [ [0 for i in range(m)] for i in range(n)] 28 | 29 | for i in range(n): 30 | line = input() 31 | for j in range(m): 32 | field[i][j] = line[j] 33 | 34 | setCounter = 0 35 | 36 | for i in range(n): 37 | for j in range(m): 38 | if used[i][j] == 0 and field[i][j] == 'X': 39 | setCounter+=1 40 | dfs(i, j, setCounter, n, m, setsNumbers, field, used, steps) 41 | 42 | for i in range(q): 43 | x, y = map(int, input().split()) 44 | x-=1 45 | y-=1 46 | if used[x][y] == 0: 47 | print("MISS") 48 | else: 49 | setsNumbers[used[x][y]]-=1 50 | if setsNumbers[used[x][y]] == 0: 51 | print("DESTROY") 52 | else: 53 | print("HIT") 54 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/go/b.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "math" 7 | "os" 8 | ) 9 | 10 | const inf int = 10e6 11 | 12 | func getFactors(n int) []int { 13 | factors := make([]int, 0, int(math.Sqrt(float64(n)))) 14 | 15 | for i := 1; i*i <= n; i++ { 16 | if n%i == 0 { 17 | factors = append(factors, i) 18 | if i != n/i { 19 | factors = append(factors, n/i) 20 | } 21 | } 22 | } 23 | 24 | return factors 25 | } 26 | 27 | func getMinChanges(str string, prev byte, factor int) int { 28 | var curMinChanges, countZero, countOne, i int 29 | for ; i < len(str); i++ { 30 | if i%factor == 0 { 31 | if prev == '0' { 32 | curMinChanges += countZero 33 | } else { 34 | curMinChanges += countOne 35 | } 36 | 37 | countZero = 0 38 | countOne = 0 39 | 40 | if i > 0 { 41 | if prev == '0' { 42 | prev = '1' 43 | } else { 44 | prev = '0' 45 | } 46 | } 47 | } 48 | 49 | if str[i] == '0' { 50 | countZero++ 51 | } else { 52 | countOne++ 53 | } 54 | } 55 | 56 | if i%factor == 0 { 57 | if prev == '0' { 58 | curMinChanges += countZero 59 | } else { 60 | curMinChanges += countOne 61 | } 62 | } 63 | 64 | return curMinChanges 65 | } 66 | 67 | func minInt(x, y int) int { 68 | if x < y { 69 | return x 70 | } 71 | return y 72 | } 73 | 74 | func main() { 75 | in := bufio.NewReader(os.Stdin) 76 | 77 | var str string 78 | fmt.Fscan(in, &str) 79 | 80 | minChanges := inf 81 | 82 | for _, factor := range getFactors(len(str)) { 83 | minChanges = minInt(minChanges, getMinChanges(str, '0', factor)) 84 | minChanges = minInt(minChanges, getMinChanges(str, '1', factor)) 85 | } 86 | 87 | fmt.Println(minChanges) 88 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/python/c.py: -------------------------------------------------------------------------------- 1 | class State: 2 | new = 0 3 | open = 1 4 | close = 3 5 | 6 | class Colour: 7 | def __init__(self): 8 | self.right_border = -1 9 | self.left_border = 1000000000 10 | self.state = State.new 11 | 12 | def solve(): 13 | m, n = map(int, input().split()) 14 | colors_line = list(map(lambda x: int(x) - 1, input().split())) 15 | colours = dict() 16 | for i in range(m): 17 | colour_id = colors_line[i] 18 | if colours.get(colour_id) is None: 19 | colours[colour_id] = Colour() 20 | if i < colours[colour_id].left_border: 21 | colours[colour_id].left_border = i 22 | if i > colours[colour_id].right_border: 23 | colours[colour_id].right_border = i 24 | stack = [] 25 | colours_ids = [] 26 | for i in range(m): 27 | colour_id = colors_line[i] 28 | if colours[colour_id].state == State.new: 29 | stack.append(i) 30 | colours[colour_id].state = State.open 31 | elif colours[colour_id].state == State.open: 32 | while colors_line[stack[-1]] != colour_id: 33 | colours_ids.append(colors_line[stack[-1]]) 34 | colours[colors_line[stack.pop()]].state = State.close 35 | elif colours[colour_id].state == State.close: 36 | print(-1) 37 | return 38 | 39 | while len(stack) > 0: 40 | colours_ids.append(colors_line[stack.pop()]) 41 | 42 | print(len(colours_ids)) 43 | colours_ids.reverse() 44 | for colour_id in colours_ids: 45 | print(f"{colour_id + 1} {colours[colour_id].left_border + 1} {colours[colour_id].right_border + 1}") 46 | 47 | if __name__ == '__main__': 48 | solve() 49 | -------------------------------------------------------------------------------- /internship_cs_feb22/jury_solutions/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | class Program 8 | { 9 | class Jelly 10 | { 11 | private int X { get; } 12 | private int Y { get; } 13 | private int R { get; } 14 | public int Z { get; } 15 | public int Index { get; } 16 | 17 | public Jelly(int x, int y, int z, int r, int index) 18 | { 19 | X = x; 20 | Y = y; 21 | Z = z; 22 | R = r; 23 | Index = index; 24 | } 25 | 26 | public bool Intersects(Jelly jelly) 27 | { 28 | return (X - jelly.X) * (X - jelly.X) 29 | + (Y - jelly.Y) * (Y - jelly.Y) 30 | <= (R + jelly.R) * (R + jelly.R); 31 | } 32 | } 33 | 34 | static void Main() 35 | { 36 | var n = int.Parse(Console.ReadLine()); 37 | var jellies = new List(n); 38 | for (int i = 0; i < n; i++) 39 | { 40 | var ints = Console.ReadLine() 41 | .Split() 42 | .Select(int.Parse) 43 | .ToArray(); 44 | var jelly = new Jelly(ints[0], ints[1], ints[2], ints[3], i + 1); 45 | jellies.Add(jelly); 46 | } 47 | 48 | jellies.Sort((x, y) => x.Z.CompareTo(y.Z)); 49 | 50 | var answer = new HashSet(); 51 | var first = jellies.FindIndex(x => x.Index == 1); 52 | answer.Add(jellies[first]); 53 | 54 | for (int i = first + 1; i < n; i++) 55 | { 56 | var nextJelly = jellies[i]; 57 | foreach (var jelly in answer) 58 | { 59 | if (jelly.Intersects(nextJelly)) 60 | { 61 | answer.Add(nextJelly); 62 | break; 63 | } 64 | } 65 | } 66 | 67 | Console.WriteLine(answer.Count); 68 | Console.WriteLine(string.Join(" ", answer.Select(x => x.Index).OrderBy(x => x))); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/go/e.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | reader := bufio.NewReader(os.Stdin) 11 | 12 | const MAXN = 1400 13 | 14 | var n, m int 15 | fmt.Fscan(reader, &n) 16 | fmt.Fscan(reader, &m) 17 | reader.ReadString('\n') 18 | 19 | var f [MAXN + 2][MAXN + 2]byte 20 | 21 | for i := 1; i <= n; i++ { 22 | line, _ := reader.ReadString('\n') 23 | for j := 1; j <= m; j++ { 24 | f[i][j] = line[j-1] - '0' 25 | } 26 | } 27 | 28 | var ul [MAXN + 2][MAXN + 2]byte 29 | for i := 1; i <= n; i++ { 30 | for j := 1; j <= m; j++ { 31 | ul[i][j] = max(f[i][j], max(ul[i-1][j], ul[i][j-1])) 32 | } 33 | } 34 | 35 | var ur [MAXN + 2][MAXN + 2]byte 36 | for i := 1; i <= n; i++ { 37 | for j := m; j >= 1; j-- { 38 | ur[i][j] = max(f[i][j], max(ur[i-1][j], ur[i][j+1])) 39 | } 40 | } 41 | 42 | var dl [MAXN + 2][MAXN + 2]byte 43 | for i := n; i >= 1; i-- { 44 | for j := 1; j <= m; j++ { 45 | dl[i][j] = max(f[i][j], max(dl[i+1][j], dl[i][j-1])) 46 | } 47 | } 48 | 49 | var dr [MAXN + 2][MAXN + 2]byte 50 | for i := n; i >= 1; i-- { 51 | for j := m; j >= 1; j-- { 52 | dr[i][j] = max(f[i][j], max(dr[i+1][j], dr[i][j+1])) 53 | } 54 | } 55 | 56 | var ans byte = 10 57 | ans_x := -1 58 | ans_y := -1 59 | 60 | for i := 1; i <= n; i++ { 61 | for j := 1; j <= m; j++ { 62 | cur_max := max( 63 | max(ul[i-1][j-1], ur[i-1][j+1]), 64 | max(dl[i+1][j-1], dr[i+1][j+1])) 65 | 66 | if cur_max < ans { 67 | ans = cur_max 68 | ans_x = i 69 | ans_y = j 70 | } 71 | } 72 | } 73 | 74 | fmt.Println(ans_x, ans_y) 75 | } 76 | 77 | func max(x, y byte) byte { 78 | if x < y { 79 | return y 80 | } 81 | return x 82 | } 83 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/python/a.py: -------------------------------------------------------------------------------- 1 | allCardsCount = 52 2 | allSuits = set("CDHS") 3 | allRanks = set("23456789TJQKA") 4 | 5 | 6 | def solve(): 7 | groups_count = list(map(int, input().split())) 8 | 9 | probability1 = calculate_probability(groups_count[0], groups_count[1]) 10 | probability2 = calculate_probability(groups_count[2], groups_count[3]) 11 | 12 | if probability1 > probability2: 13 | print(probability1) 14 | else: 15 | print(probability2) 16 | 17 | 18 | def calculate_probability(removed_groups_count, sought_groups_count): 19 | removed_cards = set() 20 | for i in range(removed_groups_count): 21 | group = set(input()) 22 | removed_cards.update(get_cards(group)) 23 | 24 | sought_cards = set() 25 | for i in range(sought_groups_count): 26 | group = set(input()) 27 | sought_cards.update(get_cards(group)) 28 | 29 | if len(removed_cards) == allCardsCount: 30 | return 0.0 31 | removed_cards_count = len(removed_cards) 32 | removed_cards.intersection_update(sought_cards) 33 | cards_intersection = len(removed_cards) 34 | return (len(sought_cards) - cards_intersection) / (allCardsCount - removed_cards_count) 35 | 36 | 37 | def get_cards(group): 38 | current_suits = set(allSuits) 39 | current_suits.intersection_update(group) 40 | if len(current_suits) == 0: 41 | current_suits = allSuits 42 | 43 | current_ranks = group.difference(current_suits) 44 | if len(current_ranks) == 0: 45 | current_ranks = allRanks 46 | 47 | cards = set() 48 | for rank in current_ranks: 49 | for suit in current_suits: 50 | cards.add(rank + suit) 51 | 52 | return cards 53 | 54 | 55 | if __name__ == '__main__': 56 | solve() 57 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/java/TaskE.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt(); 7 | int m = sc.nextInt(); 8 | sc.nextLine(); 9 | int[][] data = new int[n][m]; 10 | int[][] digitsInRow = new int[n][10]; 11 | int[][] digitsInColumn = new int[m][10]; 12 | int[] digitsInMatrix = new int[10]; 13 | 14 | for (int i = 0; i < n; i++) { 15 | String s = sc.nextLine(); 16 | for (int j = 0; j < m; j++) { 17 | int cur = s.charAt(j) - '0'; 18 | data[i][j] = cur; 19 | digitsInRow[i][cur]++; 20 | digitsInColumn[j][cur]++; 21 | digitsInMatrix[cur]++; 22 | } 23 | } 24 | 25 | int ansDigit = 9; 26 | int ansRow = 0; 27 | int ansColumn = 0; 28 | for (int i = 0; i < n; i++) { 29 | for (int j = 0; j < m; j++) { 30 | int maxNotDeleted = -1; 31 | for (int k = 9; k >= 0; k--) { 32 | int digitsInCell = data[i][j] == k ? 1 : 0; 33 | if (digitsInMatrix[k] > digitsInRow[i][k] + digitsInColumn[j][k] - digitsInCell) { 34 | maxNotDeleted = k; 35 | break; 36 | } 37 | } 38 | 39 | if (maxNotDeleted < ansDigit) { 40 | ansDigit = maxNotDeleted; 41 | ansRow = i; 42 | ansColumn = j; 43 | } 44 | } 45 | } 46 | System.out.println(String.format("%d %d", ansRow + 1, ansColumn + 1)); 47 | } 48 | } -------------------------------------------------------------------------------- /cs_schools_sep24/jury_solutions/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | public class Solution 7 | { 8 | static void Main() 9 | { 10 | new Solution().Run(); 11 | } 12 | 13 | List beautifulNumbers = new List(); 14 | 15 | void BruteForce(int now, int digits, int digitsNeed, bool[] used) 16 | { 17 | if (digits == digitsNeed) 18 | return; 19 | 20 | for (int d = digits == 0 ? 1 : 0; d <= 9; d++) 21 | if (!used[d]) 22 | { 23 | used[d] = true; 24 | int next = now * 10 + d; 25 | beautifulNumbers.Add(next); 26 | BruteForce(next, digits + 1, digitsNeed, used); 27 | used[d] = false; 28 | } 29 | } 30 | 31 | void Run() 32 | { 33 | BruteForce(0, 0, 8, new bool[10]); 34 | beautifulNumbers.Add(1000000000); 35 | var beautifulNumbersArray = beautifulNumbers.OrderBy(x => x).ToArray(); 36 | 37 | int t = ReadInts()[0]; 38 | for (int i = 0; i < t; i++) 39 | { 40 | var ints = ReadInts(); 41 | int l = ints[0]; 42 | int r = ints[1]; 43 | Console.WriteLine(CountLessThanOrEqualTo(beautifulNumbersArray, r) - CountLessThanOrEqualTo(beautifulNumbersArray, l - 1)); 44 | } 45 | } 46 | 47 | private int CountLessThanOrEqualTo(int[] array, int bound) 48 | { 49 | int index = Array.BinarySearch(array, bound); 50 | if (index < 0) 51 | return ~index; 52 | else 53 | return index + 1; 54 | } 55 | 56 | int[] ReadInts() 57 | { 58 | return Console.ReadLine().Split().Select(int.Parse).ToArray(); 59 | } 60 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/go/d.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | const charStates string = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ" 11 | 12 | func min(a, b int64) int64 { 13 | if a > b { 14 | return b 15 | } 16 | return a 17 | } 18 | 19 | func max(a, b int64) int64 { 20 | if a < b { 21 | return b 22 | } 23 | return a 24 | } 25 | 26 | func update(tree []int64, v, tl, tr, l, r, add int64) { 27 | if l > r { 28 | return 29 | } 30 | if tl == l && tr == r { 31 | tree[v] += add 32 | } else { 33 | tm := (tl + tr) / 2 34 | update(tree, v*2, tl, tm, l, min(r, tm), add) 35 | update(tree, v*2+1, tm+1, tr, max(l, tm+1), r, add) 36 | } 37 | } 38 | 39 | func get(tree []int64, v, tl, tr, pos int64) int64 { 40 | if tl == tr { 41 | return tree[v] 42 | } 43 | tm := (tl + tr) / 2 44 | if pos <= tm { 45 | return tree[v] + get(tree, v*2, tl, tm, pos) 46 | } else { 47 | return tree[v] + get(tree, v*2+1, tm+1, tr, pos) 48 | } 49 | } 50 | 51 | func buildSegTree(n int64) []int64 { 52 | segTree := make([]int64, 4*n) 53 | return segTree 54 | } 55 | 56 | func getCode(char string) int { 57 | return strings.Index(charStates, char) 58 | } 59 | 60 | func main() { 61 | in := bufio.NewReader(os.Stdin) 62 | 63 | var s string 64 | var q, l, r, val int64 65 | 66 | fmt.Fscan(in, &s, &q) 67 | n := int64(len(s)) 68 | 69 | segTree := buildSegTree(n) 70 | 71 | for i := int64(0); i < q; i++ { 72 | fmt.Fscan(in, &l, &r, &val) 73 | update(segTree, 1, 0, n-1, l-1, r-1, val) 74 | } 75 | 76 | for i := int64(0); i < n; i++ { 77 | initCode := getCode(s[i : i+1]) 78 | toAdd := get(segTree, 1, 0, n-1, i) 79 | newCode := (int64(initCode) + toAdd) % int64(len(charStates)) 80 | fmt.Print(charStates[newCode : newCode+1]) 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/python/e.py: -------------------------------------------------------------------------------- 1 | import bisect 2 | import sys 3 | 4 | def make_move(direction, distance): 5 | global current_x 6 | global current_y 7 | new_x = current_x + distance * dx[direction] 8 | new_y = current_y + distance * dy[direction] 9 | 10 | if new_x == current_x and check_intersection(current_x, current_y, new_y, points_x): 11 | return False 12 | if new_y == current_y and check_intersection(current_y, current_x, new_x, points_y): 13 | return False 14 | 15 | current_x = new_x 16 | current_y = new_y 17 | return True 18 | 19 | def check_intersection(key, start, finish, points): 20 | if key not in points: 21 | return False 22 | lst = points[key] 23 | 24 | if start > finish: 25 | start, finish = finish, start 26 | 27 | lower_bound = bisect.bisect_left(lst, start) 28 | 29 | return lower_bound < len(lst) and lst[lower_bound] <= finish 30 | 31 | 32 | dx = {'U': 0, 'D': 0, 'L': -1, 'R': 1} 33 | dy = {'U': 1, 'D': -1, 'L': 0, 'R': 0} 34 | points_x = {} 35 | points_y = {} 36 | 37 | n = int(input()) 38 | for _ in range(n): 39 | ints = list(map(int, sys.stdin.readline().split())) 40 | x = ints[0] 41 | y = ints[1] 42 | if x not in points_x: 43 | points_x[x] = [] 44 | points_x[x].append(y) 45 | if y not in points_y: 46 | points_y[y] = [] 47 | points_y[y].append(x) 48 | 49 | for x in points_x: 50 | points_x[x].sort() 51 | for y in points_y: 52 | points_y[y].sort() 53 | 54 | current_x = 0 55 | current_y = 0 56 | 57 | q = int(input()) 58 | for _ in range(1, q + 1): 59 | tokens = sys.stdin.readline().split() 60 | direction = tokens[0][0] 61 | distance = int(tokens[1]) 62 | if not make_move(direction, distance): 63 | print("Stop", _) 64 | exit() 65 | 66 | print("Complete") 67 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cpp/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int stop(int idx) { 9 | cout << "Stop " << idx; 10 | return 0; 11 | } 12 | int complete() { 13 | cout << "Complete"; 14 | return 0; 15 | } 16 | 17 | int main() { 18 | int n; 19 | cin >> n; 20 | map> by_x, by_y; 21 | int x, y; 22 | for (int i = 0; i < n; ++i) { 23 | cin >> x >> y; 24 | by_x[x].push_back(y); 25 | by_y[y].push_back(x); 26 | } 27 | for (auto& t : by_x) 28 | sort(t.second.begin(), t.second.end()); 29 | for (auto& t : by_y) 30 | sort(t.second.begin(), t.second.end()); 31 | int m, k; 32 | char dir; 33 | cin >> m; 34 | x = 0, y = 0; 35 | int end_x, end_y; 36 | for (int i = 1; i <= m; ++i) { 37 | cin >> dir >> k; 38 | if (dir == 'U') 39 | end_x = x, end_y = y + k; 40 | else if (dir == 'D') 41 | end_x = x, end_y = y - k; 42 | else if (dir == 'R') 43 | end_x = x + k, end_y = y; 44 | else 45 | end_x = x - k, end_y = y; 46 | if (x == end_x) { 47 | int y1 = y, y2 = end_y; 48 | if (y1 > y2) swap(y1, y2); 49 | 50 | auto it = lower_bound(by_x[x].begin(), by_x[x].end(), y1); 51 | if (it != by_x[x].end() && *it <= y2) 52 | return stop(i); 53 | } 54 | else { 55 | int x1 = x, x2 = end_x; 56 | if (x1 > x2) swap(x1, x2); 57 | 58 | auto it = lower_bound(by_y[y].begin(), by_y[y].end(), x1); 59 | if (it != by_y[y].end() && *it <= x2) 60 | return stop(i); 61 | } 62 | x = end_x, y = end_y; 63 | } 64 | return complete(); 65 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/python/d.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | input = sys.stdin.readline 4 | 5 | def check(n, k, border): 6 | order = [] 7 | return check_graph(n, border, order) or check_k_len_path(n, k, border, order) 8 | 9 | def check_graph(n, border, order): 10 | colors = [0] * n 11 | res = False 12 | color = 1 13 | for i in range(n): 14 | if colors[i] != 0: 15 | continue 16 | res = res or top_sort_no_rec(i, border, colors, order, color) 17 | color += 1 18 | 19 | return res 20 | 21 | def top_sort_no_rec(v, border, colors, order, cur_color): 22 | dfs = [(False, v)] 23 | while dfs: 24 | node = dfs.pop() 25 | if node[0]: 26 | order.append(node[1]) 27 | colors[node[1]] = cur_color 28 | continue 29 | 30 | if colors[node[1]] != 0: 31 | continue 32 | 33 | colors[node[1]] = -1 34 | dfs.append((True, node[1])) 35 | 36 | for u in graph[node[1]]: 37 | if u[1] > border: 38 | continue 39 | 40 | if colors[u[0]] == -1: 41 | return True 42 | 43 | if colors[u[0]] == 0: 44 | dfs.append((False, u[0])) 45 | 46 | return False 47 | 48 | def check_k_len_path(n, k, border, order): 49 | dp = [0] * n 50 | 51 | for v in order: 52 | dp[v] = 1 53 | 54 | for p in graph[v]: 55 | u = p[0] 56 | if p[1] <= border and dp[v] < dp[u] + 1: 57 | dp[v] = dp[u] + 1 58 | 59 | if dp[v] >= k: 60 | return True 61 | 62 | return False 63 | 64 | 65 | if __name__ == '__main__': 66 | nmk = input().split(' ') 67 | n = int(nmk[0]) 68 | m = int(nmk[1]) 69 | k = int(nmk[2]) + 1 70 | k = min(k, n + 1) 71 | graph = [[] for _ in range(n)] 72 | mx = 0 73 | for _ in range(m): 74 | uvc = input().split(' ') 75 | u = int(uvc[0]) - 1 76 | v = int(uvc[1]) - 1 77 | c = int(uvc[2]) 78 | graph[u].append((v, c)) 79 | mx = max(mx, c) 80 | 81 | l = 1 82 | r = mx + 2 83 | ans = -1 84 | 85 | while l <= r: 86 | mid = (l + r) // 2 87 | 88 | if check(n, k, mid): 89 | r = mid - 1 90 | ans = mid 91 | else: 92 | l = mid + 1 93 | 94 | print(ans) 95 | -------------------------------------------------------------------------------- /internship_cs_feb22/jury_solutions/e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | class Program 8 | { 9 | private static int[] a; 10 | 11 | private class MyComparer : IComparer<(int, int)> 12 | { 13 | public int Compare((int, int) pair1, (int, int) pair2) 14 | { 15 | var (left1, right1) = pair1; 16 | var (left2, right2) = pair2; 17 | if (a[right1] - a[left1] != a[right2] - a[left2]) 18 | return (a[right1] - a[left1]).CompareTo(a[right2] - a[left2]); 19 | if (a[right1] + a[left1] != a[right2] + a[left2]) 20 | return -(a[right1] + a[left1]).CompareTo(a[right2] + a[left2]); 21 | return right1.CompareTo(right2); 22 | } 23 | } 24 | 25 | static void Main() 26 | { 27 | Console.ReadLine(); 28 | a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray(); 29 | var set = new SortedSet<(int, int)>(new MyComparer()); 30 | for (int i = 0; i < a.Length - 1; i++) 31 | set.Add((i, i + 1)); 32 | 33 | var list = new LinkedList(); 34 | var map = new Dictionary>(); 35 | for (int i = 0; i < a.Length; i++) 36 | { 37 | list.AddLast(i); 38 | map[i] = list.Last; 39 | } 40 | 41 | var first = new List(); 42 | var second = new List(); 43 | while (set.Count > 0) 44 | { 45 | var (u, v) = set.Min; 46 | set.Remove(set.Min); 47 | first.Add(a[u]); 48 | second.Add(a[v]); 49 | 50 | var left = map[u].Previous; 51 | if (left != null) 52 | set.Remove((left.Value, u)); 53 | 54 | var right = map[v].Next; 55 | if (right != null) 56 | set.Remove((v, right.Value)); 57 | 58 | if (left != null && right != null) 59 | set.Add((left.Value, right.Value)); 60 | 61 | list.Remove(map[u]); 62 | list.Remove(map[v]); 63 | } 64 | 65 | Console.WriteLine(string.Join(" ", second)); 66 | Console.WriteLine(string.Join(" ", first)); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /hiring_days_cs_nov23/jury_solutions/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | Console.ReadLine(); 10 | var train = new[] {ReadInts(), ReadInts()}; 11 | int n = train[0].Length; 12 | var isGoodPrefix = new bool[n, 2]; 13 | var parent = new int[n, 2]; 14 | 15 | parent[0, 0] = -1; 16 | parent[0, 1] = -1; 17 | isGoodPrefix[0, 0] = true; 18 | isGoodPrefix[0, 1] = true; 19 | 20 | for (int i = 0; i < n - 1; i++) 21 | { 22 | for (int j = 0; j < 2; j++) 23 | { 24 | for (int k = 0; k < 2; k++) 25 | { 26 | if (isGoodPrefix[i, j] && train[k][i + 1] > train[j][i] && train[1 - k][i + 1] < train[1 - j][i]) 27 | { 28 | isGoodPrefix[i + 1, k] = true; 29 | parent[i + 1, k] = j; 30 | } 31 | } 32 | } 33 | } 34 | 35 | int last = -1; 36 | for (int i = 0; i < 2; i++) 37 | if (isGoodPrefix[n - 1, i]) 38 | last = i; 39 | 40 | if (last == -1) 41 | { 42 | Console.WriteLine(-1); 43 | return; 44 | } 45 | 46 | List ans = new List(); 47 | int current = n - 1; 48 | while (last != -1) 49 | { 50 | if (last == 1) 51 | ans.Add(current + 1); 52 | last = parent[current, last]; 53 | current--; 54 | } 55 | 56 | ans.Reverse(); 57 | Console.WriteLine(ans.Count); 58 | Console.WriteLine(string.Join(" ", ans)); 59 | } 60 | 61 | private static int[] ReadInts() 62 | { 63 | return Console.ReadLine() 64 | .Split() 65 | .Select(int.Parse) 66 | .ToArray(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /cs_schools_oct_23/jury_solutions/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | class Program 6 | { 7 | public static void Main() 8 | { 9 | var n = int.Parse(Console.ReadLine()); 10 | var a = new List[n]; 11 | var order = new SortedDictionary(); 12 | for (var i = 0; i < n; i++) 13 | { 14 | var input = Console.ReadLine().Split(); 15 | var m = int.Parse(input[0]); 16 | 17 | a[i] = new List(); 18 | for (var j = 1; j <= m; j++) 19 | a[i].Add(int.Parse(input[j])); 20 | 21 | var arr = a[i].ToArray(); 22 | var isSorted = IsSorted(arr); 23 | if (isSorted) 24 | { 25 | if (order.ContainsKey(arr[0])) 26 | { 27 | Console.WriteLine(-1); 28 | return; 29 | } 30 | 31 | order[arr[0]] = i; 32 | continue; 33 | } 34 | 35 | arr = arr.Reverse().ToArray(); 36 | isSorted = IsSorted(arr); 37 | if (isSorted) 38 | { 39 | if (order.ContainsKey(arr[0])) 40 | { 41 | Console.WriteLine(-1); 42 | return; 43 | } 44 | 45 | order[arr[0]] = i; 46 | a[i] = arr.ToList(); 47 | continue; 48 | } 49 | 50 | Console.WriteLine(-1); 51 | return; 52 | } 53 | 54 | var ans = new List(); 55 | foreach (var i in order.Values) 56 | ans.AddRange(a[i]); 57 | 58 | if (IsSorted(ans.ToArray())) 59 | Console.WriteLine(string.Join(" ", ans)); 60 | else 61 | Console.WriteLine(-1); 62 | } 63 | 64 | private static bool IsSorted(int[] a) 65 | { 66 | for (var i = 1; i < a.Length; i++) 67 | if (a[i - 1] >= a[i]) 68 | return false; 69 | return true; 70 | } 71 | } -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/cs/e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | 6 | namespace ConsoleApp2 7 | { 8 | public class Program 9 | { 10 | private static void Solve() 11 | { 12 | var tokens = Console.ReadLine() 13 | .Split(); 14 | var n = int.Parse(tokens[0]); 15 | var m = int.Parse(tokens[1]); 16 | 17 | var a = new int[n][]; 18 | 19 | var list = new List<(int, int, int)>(); 20 | 21 | for (int i = 0; i < n; i++) 22 | { 23 | a[i] = Console.ReadLine() 24 | .Select(s => s - '0') 25 | .ToArray(); 26 | 27 | for (int j = 0; j < m; j++) 28 | list.Add((a[i][j], i, j)); 29 | } 30 | 31 | list.Sort((x, y) => y.Item1.CompareTo(x.Item1)); 32 | if (list[0].Item2 != list[1].Item2 && 33 | list[0].Item3 != list[1].Item3 34 | ) 35 | { 36 | int max1 = Check(a, list[0].Item2, list[1].Item3); 37 | int max2 = Check(a, list[1].Item2, list[0].Item3); 38 | if (max1 < max2) 39 | Console.WriteLine("{0} {1}", list[0].Item2 + 1, list[1].Item3 + 1); 40 | else 41 | Console.WriteLine("{0} {1}", list[1].Item2 + 1, list[0].Item3 + 1); 42 | return; 43 | } 44 | 45 | if (list[0].Item2 == list[1].Item2) 46 | { 47 | for (int i = 2; i < n * m; i++) 48 | if (list[i].Item2 != list[0].Item2) 49 | { 50 | Console.WriteLine("{0} {1}", list[0].Item2 + 1, list[i].Item3 + 1); 51 | return; 52 | } 53 | } 54 | 55 | if (list[0].Item3 == list[1].Item3) 56 | { 57 | for (int i = 2; i < n * m; i++) 58 | if (list[i].Item3 != list[0].Item3) 59 | { 60 | Console.WriteLine("{0} {1}", list[i].Item2 + 1, list[0].Item3 + 1); 61 | return; 62 | } 63 | } 64 | } 65 | 66 | private static int Check(int[][] a, int row, int column) 67 | { 68 | int max = -1; 69 | for (int i = 0; i < a.Length; i++) 70 | for (int j = 0; j < a[0].Length; j++) 71 | if (i != row && j != column && a[i][j] > max) 72 | max = a[i][j]; 73 | 74 | return max; 75 | } 76 | 77 | public static void Main() 78 | { 79 | var T = new Thread(Solve, 10000000); 80 | T.Start(); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/go/d.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "cmp" 6 | "fmt" 7 | "os" 8 | "slices" 9 | "strings" 10 | ) 11 | 12 | func main() { 13 | err := taskD() 14 | if err != nil { 15 | fmt.Printf("err: %s\n", err.Error()) 16 | } 17 | } 18 | 19 | func taskD() error { 20 | scanner := bufio.NewScanner(os.Stdin) 21 | buf := make([]byte, 0, 64*1024) 22 | scanner.Buffer(buf, 20*1024*1024) 23 | 24 | n, m := Read2Int(scanner) 25 | _, _ = n, m 26 | 27 | u, v := Read2Int(scanner) 28 | us := ReadArray(scanner, u) 29 | vs := ReadArray(scanner, v) 30 | 31 | slices.Sort[[]int](us) 32 | slices.Sort[[]int](vs) 33 | 34 | q := ReadInt(scanner) 35 | 36 | for _ = range q { 37 | x_1, y_1, x_2, y_2 := Read4Int(scanner) 38 | 39 | rx_1 := GetRegion(us, x_1) 40 | ry_1 := GetRegion(vs, y_1) 41 | 42 | rx_2 := GetRegion(us, x_2) 43 | ry_2 := GetRegion(vs, y_2) 44 | 45 | if rx_1 == rx_2 && ry_1 == ry_2 { 46 | fmt.Printf("YES\n") 47 | } else { 48 | fmt.Printf("NO\n") 49 | } 50 | } 51 | 52 | return nil 53 | } 54 | 55 | func GetRegion(x []int, target int) int { 56 | n := len(x) 57 | i, j := 0, n 58 | for i < j { 59 | h := int(uint(i+j) >> 1) 60 | if cmp.Less(x[h], target) { 61 | i = h + 1 62 | } else { 63 | j = h 64 | } 65 | } 66 | return i 67 | } 68 | 69 | func Read4Int(scanner *bufio.Scanner) (x_1, y_1, x_2, y_2 int) { 70 | scanner.Scan() 71 | fmt.Sscanf(scanner.Text(), "%d %d %d %d", &x_1, &y_1, &x_2, &y_2) 72 | return 73 | } 74 | 75 | func ReadArray(scanner *bufio.Scanner, n int) []int { 76 | scanner.Scan() 77 | arr := strings.Split(scanner.Text(), " ") 78 | result := make([]int, 0, len(arr)) 79 | for _, str := range arr { 80 | result = append(result, toInt(str)) 81 | } 82 | return result 83 | } 84 | 85 | func ReadInt(scanner *bufio.Scanner) int { 86 | scanner.Scan() 87 | return toInt(scanner.Text()) 88 | } 89 | 90 | func Read2Int(scanner *bufio.Scanner) (a int, b int) { 91 | scanner.Scan() 92 | fmt.Sscanf(scanner.Text(), "%d %d", &a, &b) 93 | return 94 | } 95 | 96 | func toInt(buf string) int { 97 | n := 0 98 | for _, v := range buf { 99 | n = n*10 + int(v-'0') 100 | } 101 | return n 102 | } 103 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/cpp/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | const int NEW = 0; 10 | const int OPEN = 1; 11 | const int CLOSE = 2; 12 | 13 | struct colour 14 | { 15 | int right_border, left_border, state; 16 | 17 | colour (int _right_border, int _left_border, int _state) 18 | : right_border(_right_border), left_border(_left_border), state(_state) 19 | { 20 | } 21 | 22 | colour() = default; 23 | }; 24 | 25 | map colours; 26 | 27 | int main () 28 | { 29 | int m, n; 30 | cin >> m >> n; 31 | 32 | vector colours_line; 33 | for (int i = 0; i < m; i++) 34 | { 35 | int c; 36 | cin >> c; 37 | colours_line.push_back(c - 1); 38 | } 39 | 40 | for (int i = 0; i < m; i++) 41 | { 42 | auto colour_id = colours_line[i]; 43 | if (colours.count(colour_id) == 0) 44 | colours[colour_id] = colour(-1, INT32_MAX, NEW); 45 | 46 | if (i < colours[colour_id].left_border) 47 | colours[colour_id].left_border = i; 48 | if (i > colours[colour_id].right_border) 49 | colours[colour_id].right_border = i; 50 | } 51 | 52 | stack stack; 53 | vector colours_ids; 54 | for (int i = 0; i < m; i++) 55 | { 56 | auto colour_id = colours_line[i]; 57 | switch (colours[colour_id].state) 58 | { 59 | case NEW: 60 | stack.push(i); 61 | colours[colour_id].state = OPEN; 62 | break; 63 | case OPEN: 64 | { 65 | while (colours_line[stack.top()] != colour_id) 66 | { 67 | colours_ids.push_back(colours_line[stack.top()]); 68 | colours[colours_line[stack.top()]].state = CLOSE; 69 | stack.pop(); 70 | } 71 | 72 | break; 73 | } 74 | case CLOSE: 75 | cout << -1 << endl; 76 | return 0; 77 | } 78 | } 79 | 80 | while (!stack.empty()) 81 | { 82 | colours_ids.push_back(colours_line[stack.top()]); 83 | stack.pop(); 84 | } 85 | 86 | cout << colours_ids.size() << endl; 87 | reverse(colours_ids.begin(), colours_ids.end()); 88 | for (auto colour_id : colours_ids) 89 | { 90 | cout << colour_id + 1 << " " << colours[colour_id].left_border + 1 << " " << colours[colour_id].right_border + 1 << endl; 91 | } 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/go/e.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "sort" 8 | ) 9 | 10 | func binarySearchOnRange(arr []int, a, b int) bool { 11 | low, high := 0, len(arr)-1 12 | 13 | for low <= high { 14 | mid := (low + high) / 2 15 | 16 | if arr[mid] >= a && arr[mid] <= b { 17 | return true 18 | } else if arr[mid] < a { 19 | low = mid + 1 20 | } else { 21 | high = mid - 1 22 | } 23 | } 24 | 25 | return false 26 | } 27 | 28 | // O(n * log(n)) 29 | func main() { 30 | in := bufio.NewReader(os.Stdin) 31 | 32 | var n int 33 | fmt.Fscan(in, &n) 34 | 35 | x := make(map[int][]int, n) 36 | y := make(map[int][]int, n) 37 | 38 | for i := 0; i < n; i++ { 39 | var xi, yi int 40 | fmt.Fscan(in, &xi, &yi) 41 | 42 | arr := x[xi] 43 | arr = append(arr, yi) 44 | x[xi] = arr 45 | 46 | arr = y[yi] 47 | arr = append(arr, xi) 48 | y[yi] = arr 49 | } 50 | 51 | for _, arr := range x { 52 | sort.Slice(arr, func(i, j int) bool { 53 | return arr[i] < arr[j] 54 | }) 55 | } 56 | 57 | for _, arr := range y { 58 | sort.Slice(arr, func(i, j int) bool { 59 | return arr[i] < arr[j] 60 | }) 61 | } 62 | 63 | var q int 64 | fmt.Fscan(in, &q) 65 | 66 | var x0, y0 int 67 | 68 | for i := 0; i < q; i++ { 69 | var dir string 70 | var k int 71 | 72 | fmt.Fscan(in, &dir, &k) 73 | 74 | switch dir { 75 | case "U": 76 | if yi, inX := x[x0]; inX && binarySearchOnRange(yi, y0, y0+k) { 77 | fmt.Println("Stop ", i+1) 78 | return 79 | } 80 | 81 | y0 += k 82 | 83 | case "D": 84 | if yi, inX := x[x0]; inX && binarySearchOnRange(yi, y0-k, y0) { 85 | fmt.Println("Stop ", i+1) 86 | return 87 | } 88 | 89 | y0 -= k 90 | 91 | case "R": 92 | if xi, inY := y[y0]; inY && binarySearchOnRange(xi, x0, x0+k) { 93 | fmt.Println("Stop ", i+1) 94 | return 95 | } 96 | 97 | x0 += k 98 | 99 | case "L": 100 | if xi, inY := y[y0]; inY && binarySearchOnRange(xi, x0-k, x0) { 101 | fmt.Println("Stop ", i+1) 102 | return 103 | } 104 | 105 | x0 -= k 106 | } 107 | } 108 | 109 | fmt.Println("Complete") 110 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/java/TaskB.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.nio.charset.StandardCharsets; 3 | import java.util.Scanner; 4 | 5 | public class TaskB { 6 | 7 | public int calculateMinChanges() { 8 | return calculateMinChanges(System.in); 9 | } 10 | 11 | int calculateMinChanges(String input) { 12 | return calculateMinChanges(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8))); 13 | } 14 | 15 | private int calculateMinChanges(InputStream inputStream) { 16 | try (Scanner scanner = new Scanner(inputStream)) { 17 | return calculateMinChangesForString(scanner.next()); 18 | } 19 | } 20 | 21 | private int calculateMinChangesForString(String sourceString) { 22 | int length = sourceString.length(); 23 | int candidate = Integer.MAX_VALUE; 24 | for (int l = 1; l <= length; l ++) { 25 | if (length % l == 0) { 26 | int minChanges = calculateMinChangesForLen(l, sourceString); 27 | candidate = Integer.min(candidate, minChanges); 28 | } 29 | } 30 | 31 | return candidate; 32 | } 33 | 34 | private int calculateMinChangesForLen(int rangeLen, String sourceString) { 35 | int rangesCount = sourceString.length() / rangeLen; 36 | 37 | int changesWithZeroesStart = 0; 38 | int changesWithOnesStart = 0; 39 | for (int i = 0; i < rangesCount; i++) { 40 | int zeros = 0; 41 | int ones = 0; 42 | 43 | for (int j = 0; j < rangeLen; j++) { 44 | char c = sourceString.charAt(j + i * rangeLen); 45 | if (c == '0') { 46 | zeros++; 47 | } 48 | 49 | if (c == '1') { 50 | ones++; 51 | } 52 | } 53 | 54 | changesWithOnesStart += (i % 2 == 0 ? ones : zeros); 55 | changesWithZeroesStart += (i % 2 == 0 ? zeros : ones); 56 | } 57 | 58 | return Math.min(changesWithZeroesStart, changesWithOnesStart); 59 | } 60 | 61 | public static void main(String[] args) { 62 | int result = new TaskB().calculateMinChanges(); 63 | System.out.print(result); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/go/e.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | 11 | err := taskD() 12 | if err != nil { 13 | fmt.Printf("err: %s\n", err.Error()) 14 | } 15 | } 16 | 17 | func taskD() error { 18 | scanner := bufio.NewScanner(os.Stdin) 19 | buf := make([]byte, 0, 64*1024) 20 | scanner.Buffer(buf, 20*1024*1024) 21 | 22 | m, n, q := Read3Int(scanner) 23 | 24 | matrix := make([]int, m*n) 25 | for i := range m { 26 | scanner.Scan() 27 | for j, char := range scanner.Text() { 28 | if char == '.' { 29 | matrix[i*n+j] = 0 30 | } else { 31 | matrix[i*n+j] = -1 32 | } 33 | } 34 | } 35 | 36 | ships := make([]int, 0) 37 | for y := range m { 38 | for x := range n { 39 | if matrix[y*n+x] == -1 { 40 | shipIdx := len(ships) + 1 41 | ships = append(ships, FillIdx(matrix, m, n, x, y, shipIdx)) 42 | } 43 | } 44 | } 45 | 46 | for _ = range q { 47 | y, x := Read2Int(scanner) 48 | x -= 1 49 | y -= 1 50 | idx := y*n + x 51 | if matrix[idx] != 0 { 52 | ships[matrix[idx]-1] -= 1 53 | ship := ships[matrix[idx]-1] 54 | matrix[idx] = 0 55 | 56 | if ship == 0 { 57 | fmt.Printf("DESTROY\n") 58 | } else { 59 | fmt.Printf("HIT\n") 60 | } 61 | } else { 62 | fmt.Printf("MISS\n") 63 | } 64 | } 65 | 66 | return nil 67 | } 68 | 69 | func Print(matrix []int, m, n int) { 70 | for i := range m { 71 | for j := range n { 72 | fmt.Printf("%v", matrix[n*i+j]) 73 | } 74 | fmt.Printf("\n") 75 | } 76 | fmt.Printf("\n") 77 | } 78 | 79 | func FillIdx(matrix []int, m, n, x, y, shipIdx int) int { 80 | if x < 0 || x >= n || y < 0 || y >= m { 81 | return 0 82 | } 83 | 84 | idx := y*n + x 85 | 86 | if matrix[idx] != -1 { 87 | return 0 88 | } 89 | 90 | matrix[idx] = shipIdx 91 | 92 | return FillIdx(matrix, m, n, x+1, y, shipIdx) + 93 | FillIdx(matrix, m, n, x, y+1, shipIdx) + 94 | FillIdx(matrix, m, n, x-1, y, shipIdx) + 95 | FillIdx(matrix, m, n, x, y-1, shipIdx) + 1 96 | } 97 | 98 | func Read3Int(scanner *bufio.Scanner) (a, b, c int) { 99 | scanner.Scan() 100 | fmt.Sscanf(scanner.Text(), "%d %d %d", &a, &b, &c) 101 | return 102 | } 103 | 104 | func Read2Int(scanner *bufio.Scanner) (a int, b int) { 105 | scanner.Scan() 106 | fmt.Sscanf(scanner.Text(), "%d %d", &a, &b) 107 | return 108 | } 109 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/java/C.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class C { 5 | public static void main(String[] args) throws Exception { 6 | new C().run(); 7 | } 8 | 9 | enum State { 10 | New, 11 | Open, 12 | Close, 13 | } 14 | 15 | private class Colour { 16 | public Colour() { 17 | rightBorder = -1; 18 | leftBorder = Integer.MAX_VALUE; 19 | state = State.New; 20 | } 21 | 22 | public int rightBorder; 23 | public int leftBorder; 24 | public State state; 25 | } 26 | 27 | private final Map colours = new HashMap<>(); 28 | 29 | StreamTokenizer in; 30 | 31 | int nextInt() throws Exception { 32 | in.nextToken(); 33 | return (int)in.nval; 34 | } 35 | 36 | public void run() throws Exception { 37 | in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); 38 | int m = nextInt(); 39 | int n = nextInt(); 40 | int[] colorsLine = new int[m]; 41 | for (int i = 0; i < m; i++) 42 | colorsLine[i] = nextInt() - 1; 43 | 44 | for (int i = 0; i < m; i++) { 45 | int colourId = colorsLine[i]; 46 | Colour colour = new Colour(); 47 | colours.putIfAbsent(colourId, colour); 48 | if (i < colours.get(colourId).leftBorder) 49 | colours.get(colourId).leftBorder = i; 50 | if (i > colours.get(colourId).rightBorder) 51 | colours.get(colourId).rightBorder = i; 52 | } 53 | 54 | Stack stack = new Stack<>(); 55 | List coloursIds = new ArrayList<>(m); 56 | for (int i = 0; i < m; i++) { 57 | int colourId = colorsLine[i]; 58 | switch (colours.get(colourId).state) { 59 | case New: 60 | stack.push(i); 61 | colours.get(colourId).state = State.Open; 62 | break; 63 | case Open: 64 | while (colorsLine[stack.peek()] != colourId) { 65 | coloursIds.add(colorsLine[stack.peek()]); 66 | colours.get(colorsLine[stack.pop()]).state = State.Close; 67 | } 68 | break; 69 | case Close: 70 | System.out.println(-1); 71 | return; 72 | } 73 | } 74 | 75 | while (!stack.isEmpty()) 76 | coloursIds.add(colorsLine[stack.pop()]); 77 | 78 | System.out.println(coloursIds.size()); 79 | Collections.reverse(coloursIds); 80 | for (int colourId : coloursIds) 81 | System.out.println((colourId + 1) + " " + (colours.get(colourId).leftBorder + 1) + " " + (colours.get(colourId).rightBorder + 1)); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /internship_cs_mar23/jury_solutions/java/TaskB.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | import java.util.HashSet; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Scanner; 7 | import java.util.Set; 8 | 9 | public class TaskB { 10 | static Map> verticals = new HashMap<>(); 11 | static Map> horizontals = new HashMap<>(); 12 | 13 | public static void main(String[] args) { 14 | Scanner sc = new Scanner(System.in); 15 | int n = sc.nextInt(); 16 | sc.nextLine(); 17 | for (int i = 0; i < n; i++) { 18 | String[] point = sc.nextLine().split(" "); 19 | int x = Integer.parseInt(point[0]); 20 | int y = Integer.parseInt(point[1]); 21 | if (!verticals.containsKey(x)) { 22 | verticals.put(x, new ArrayList<>()); 23 | } 24 | verticals.get(x).add(y); 25 | if (!horizontals.containsKey(y)) { 26 | horizontals.put(y, new HashSet<>()); 27 | } 28 | horizontals.get(y).add(x); 29 | } 30 | solve(verticals, horizontals); 31 | } 32 | 33 | private static void solve(Map> verticals, Map> horizontals) { 34 | long maxSquare = 0; 35 | for (int startX: verticals.keySet()) { 36 | List startRow = verticals.get(startX); 37 | if (startRow.size() > 1) { 38 | for (int i = 0; i < startRow.size(); i++) { 39 | int startY = startRow.get(i); 40 | for (int j = i + 1; j < startRow.size(); j++) { 41 | int endY = startRow.get(j); 42 | for (int endX: horizontals.get(startY)) { 43 | if (horizontals.get(endY).contains(endX)) { 44 | long square = getSquare(startX, endX, startY, endY); 45 | maxSquare = Math.max(square, maxSquare); 46 | } 47 | } 48 | } 49 | } 50 | } 51 | } 52 | System.out.println(maxSquare); 53 | } 54 | private static long getSquare(int startX, int endX, int startY, int endY) { 55 | long dX = Math.abs(startX - endX); 56 | long dY = Math.abs(startY - endY); 57 | return dX * dY; 58 | } 59 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/go/c.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "slices" 7 | "strconv" 8 | "strings" 9 | ) 10 | import "bufio" 11 | 12 | type Colour struct { 13 | rightBorder int 14 | leftBorder int 15 | state State 16 | } 17 | 18 | type State int 19 | 20 | const ( 21 | New State = iota 22 | Open 23 | Close 24 | ) 25 | 26 | func main() { 27 | scanner := bufio.NewScanner(os.Stdin) 28 | scanner.Buffer(make([]byte, 5000000), 5000000) 29 | 30 | var m, n int 31 | scanner.Scan() 32 | fmt.Sscan(scanner.Text(), &m, &n) 33 | coloursLine := make([]int, 0) 34 | scanner.Scan() 35 | line := scanner.Text() 36 | for _, colourString := range strings.Split(line, " ") { 37 | colourId, _ := strconv.Atoi(colourString) 38 | coloursLine = append(coloursLine, colourId-1) 39 | } 40 | 41 | colours := make(map[int]*Colour) 42 | for i := 0; i < m; i++ { 43 | colourId := coloursLine[i] 44 | if _, exists := colours[colourId]; !exists { 45 | colours[colourId] = &Colour{rightBorder: -1, leftBorder: 1000000000, state: New} 46 | } 47 | 48 | colour, _ := colours[colourId] 49 | if i < colour.leftBorder { 50 | colour.leftBorder = i 51 | } 52 | if i > colour.rightBorder { 53 | colour.rightBorder = i 54 | } 55 | } 56 | 57 | stack := make([]int, 0) 58 | coloursIds := make([]int, 0) 59 | 60 | for i := 0; i < m; i++ { 61 | colourIndex := coloursLine[i] 62 | switch colour, _ := colours[colourIndex]; colour.state { 63 | case New: 64 | stack = append(stack, i) 65 | colour.state = Open 66 | case Open: 67 | for coloursLine[stack[len(stack)-1]] != colourIndex { 68 | coloursIds = append(coloursIds, coloursLine[stack[len(stack)-1]]) 69 | colour2, _ := colours[coloursLine[stack[len(stack)-1]]] 70 | colour2.state = Close 71 | stack = stack[:len(stack)-1] 72 | } 73 | case Close: 74 | fmt.Println(-1) 75 | return 76 | } 77 | } 78 | 79 | for len(stack) > 0 { 80 | coloursIds = append(coloursIds, coloursLine[stack[len(stack)-1]]) 81 | stack = stack[:len(stack)-1] 82 | } 83 | fmt.Println(len(coloursIds)) 84 | slices.Reverse(coloursIds) 85 | for _, colourId := range coloursIds { 86 | colour, _ := colours[colourId] 87 | id := strconv.Itoa(colourId + 1) 88 | leftBoarder := strconv.Itoa(colour.leftBorder + 1) 89 | rightBorder := strconv.Itoa(colour.rightBorder + 1) 90 | fmt.Println(id + " " + leftBoarder + " " + rightBorder) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /hiring_days_cs_nov21/jury_solutions/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApp 6 | { 7 | public class Program 8 | { 9 | private class Rule 10 | { 11 | public Rule(string word, int hyphenIndex) 12 | { 13 | Word = word; 14 | HyphenIndex = hyphenIndex; 15 | } 16 | 17 | public string Word { get; } 18 | public int HyphenIndex { get; } 19 | } 20 | 21 | static void Main() 22 | { 23 | var ints = Console.ReadLine() 24 | .Split() 25 | .Select(int.Parse) 26 | .ToArray(); 27 | int rulesCount = ints[0]; 28 | int width = ints[1]; 29 | var rules = new List(rulesCount); 30 | for (int i = 0; i < rulesCount; i++) 31 | { 32 | var wordParts = Console.ReadLine().Split('-'); 33 | var rule = new Rule(string.Concat(wordParts), wordParts[0].Length); 34 | rules.Add(rule); 35 | } 36 | 37 | ProcessLine(Console.ReadLine(), width, rules); 38 | } 39 | 40 | private static void ProcessLine(string line, int width, List rules) 41 | { 42 | int start = 0; 43 | 44 | while (start < line.Length) 45 | { 46 | if (line.Length - start <= width) 47 | { 48 | Console.WriteLine(line.Substring(start)); 49 | break; 50 | } 51 | 52 | if (!char.IsLetter(line[start + width])) 53 | { 54 | Console.WriteLine(line.Substring(start, width)); 55 | start += width; 56 | continue; 57 | } 58 | 59 | int wordStart = start + width; 60 | while (wordStart > start && char.IsLetter(line[wordStart - 1])) 61 | wordStart--; 62 | 63 | int wordEnd = start + width; 64 | while (wordEnd < line.Length && char.IsLetter(line[wordEnd])) 65 | wordEnd++; 66 | 67 | var word = line.Substring(wordStart, wordEnd - wordStart); 68 | var bestRule = GetBestHyphenIndex(word, start + width - wordStart, rules); 69 | var hyphenIndex = bestRule?.HyphenIndex ?? 0; 70 | Console.Write(line.Substring(start, wordStart - start + hyphenIndex)); 71 | Console.WriteLine(bestRule != null ? "-" : ""); 72 | 73 | start = wordStart + hyphenIndex; 74 | } 75 | } 76 | 77 | private static Rule GetBestHyphenIndex(string word, int lengthLeft, List rules) 78 | { 79 | return rules 80 | .Where(rule => word.Equals(rule.Word, StringComparison.OrdinalIgnoreCase) && rule.HyphenIndex < lengthLeft) 81 | .OrderByDescending(rule => rule.HyphenIndex) 82 | .FirstOrDefault(); 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cpp/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::vector> steps{{1, 0}, 4 | {-1, 0}, 5 | {0, 1}, 6 | {0, -1}}; 7 | 8 | bool is_in_bounds(int x, int y, int n, int m) { 9 | return x >= 0 && x < n && y >= 0 && y < m; 10 | } 11 | 12 | void dfs(int startX, int startY, int setNumber, int n, int m, 13 | std::vector &setsNumbers, 14 | std::vector> &field, 15 | std::vector> &used) { 16 | 17 | std::vector> stack; 18 | stack.emplace_back(startX, startY); 19 | used[startX][startY] = setNumber; 20 | 21 | while(!stack.empty()) { 22 | auto current = stack[stack.size() - 1]; 23 | stack.pop_back(); 24 | setsNumbers[setNumber]++; 25 | 26 | for (auto& step : steps) { 27 | int posX = current.first + step.first; 28 | int posY = current.second + step.second; 29 | 30 | if (is_in_bounds(posX, posY, n, m) && field[posX][posY] == 'X' && used[posX][posY] == 0) { 31 | stack.emplace_back(posX, posY); 32 | used[posX][posY] = setNumber; 33 | } 34 | } 35 | } 36 | } 37 | 38 | int main() { 39 | int n, m, q; 40 | std::cin >> n >> m >> q; 41 | 42 | std::vector setsNumbers(n * m, 0); 43 | std::vector> field(n, std::vector(m, '.')); 44 | std::vector> used(n, std::vector(m, 0)); 45 | 46 | for (int i = 0; i < n; i++) { 47 | std::string line; 48 | std::cin >> line; 49 | for (int j = 0; j < m; j++) { 50 | field[i][j] = line[j]; 51 | } 52 | } 53 | 54 | int setCounter = 0; 55 | 56 | for (int i = 0; i < n; i++) 57 | for (int j = 0; j < m; j++) { 58 | if (used[i][j] == 0 && field[i][j] == 'X') { 59 | setCounter++; 60 | dfs(i, j, setCounter, n, m, setsNumbers, field, used); 61 | } 62 | } 63 | 64 | while (q--) { 65 | int x, y; 66 | std::cin >> x >> y; 67 | x--; 68 | y--; 69 | if (used[x][y] == 0) 70 | std::cout << "MISS" << '\n'; 71 | else { 72 | setsNumbers[used[x][y]]--; 73 | std::string result = setsNumbers[used[x][y]] == 0 ? "DESTROY" : "HIT"; 74 | std::cout << result << '\n'; 75 | } 76 | } 77 | return 0; 78 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/cpp/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | const int allCardsCount = 52; 10 | const set all_suits = { 'C', 'D', 'H', 'S' }; 11 | const set all_ranks = { '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' }; 12 | 13 | vector read_cardsets (int size) 14 | { 15 | vector cardsets; 16 | string cardset; 17 | for (int i = 0; i < size; i++) 18 | { 19 | cin >> cardset; 20 | cardsets.push_back(cardset); 21 | } 22 | return cardsets; 23 | } 24 | 25 | bool cardset_contains_card (string cardset, char suit, char rank) 26 | { 27 | set suits_in_set; 28 | set ranks_in_set; 29 | for (char c : cardset) 30 | { 31 | if (all_suits.count(c) != 0) 32 | suits_in_set.insert(c); 33 | else 34 | ranks_in_set.insert(c); 35 | } 36 | if (suits_in_set.empty()) 37 | suits_in_set = all_suits; 38 | if (ranks_in_set.empty()) 39 | ranks_in_set = all_ranks; 40 | 41 | return suits_in_set.count(suit) != 0 && ranks_in_set.count(rank) != 0; 42 | } 43 | 44 | bool cardsets_contains_card (vector cardsets, char suit, char rank) 45 | { 46 | for (auto cardset : cardsets) 47 | { 48 | if (cardset_contains_card(cardset, suit, rank)) 49 | return true; 50 | } 51 | 52 | return false; 53 | } 54 | 55 | double calculate_probability (vector removed_cardsets, vector checked_cardsets) 56 | { 57 | int all_not_removed_count = 0; 58 | int checked_not_removed_count = 0; 59 | for (char suit : all_suits) 60 | { 61 | for (char rank : all_ranks) 62 | { 63 | if (!cardsets_contains_card(removed_cardsets, suit, rank)) 64 | { 65 | all_not_removed_count++; 66 | 67 | if (cardsets_contains_card(checked_cardsets, suit, rank)) 68 | checked_not_removed_count++; 69 | } 70 | } 71 | } 72 | 73 | return all_not_removed_count == 0 ? 0.0 : checked_not_removed_count / (double)(all_not_removed_count); 74 | } 75 | 76 | int main () 77 | { 78 | int r1, s1, r2, s2; 79 | cin >> r1 >> s1 >> r2 >> s2; 80 | 81 | auto removed_cardsets1 = read_cardsets(r1); 82 | auto checked_cardsets1 = read_cardsets(s1); 83 | 84 | auto removed_cardsets2 = read_cardsets(r2); 85 | auto checked_cardsets2 = read_cardsets(s2); 86 | 87 | double probability1 = calculate_probability(removed_cardsets1, checked_cardsets1); 88 | double probability2 = calculate_probability(removed_cardsets2, checked_cardsets2); 89 | 90 | cout << max(probability1, probability2); 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cs/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Summer2024 5 | { 6 | class Program 7 | { 8 | static void Main() 9 | { 10 | var solution = new Solution(); 11 | solution.Solve(); 12 | } 13 | } 14 | public class Solution 15 | { 16 | public Solution() 17 | { 18 | (n, q) = Read2Int(); 19 | rows = new int[n + 2]; 20 | columns = new int[n + 2]; 21 | rows[0] = rows[n + 1] = columns[0] = columns[n + 1] = 1; 22 | (verticalSplits, horizontalSplits) = (2, 2); 23 | } 24 | 25 | public void Solve() 26 | { 27 | for (var i = 0; i < q; i++) 28 | { 29 | var input = Console.ReadLine().Split(' ').ToArray(); 30 | var (type, x, y) = (input[0], int.Parse(input[1]), int.Parse(input[2])); 31 | 32 | if (type == "+") 33 | { 34 | UpdateState(x, y, type); 35 | rows[x]++; 36 | columns[y]++; 37 | } 38 | else 39 | { 40 | rows[x]--; 41 | columns[y]--; 42 | UpdateState(x, y, type); 43 | } 44 | 45 | Console.WriteLine(((long)horizontalSplits - 1) * (verticalSplits - 1)); 46 | } 47 | } 48 | 49 | private void UpdateState(int x, int y, string type) 50 | { 51 | if (rows[x] == 0) 52 | { 53 | if (rows[x - 1] != 0 && rows[x + 1] != 0) 54 | horizontalSplits -= type == "+" ? 1 : -1; 55 | else if (rows[x - 1] == 0 && rows[x + 1] == 0) 56 | horizontalSplits += type == "+" ? 1 : -1; 57 | } 58 | 59 | if (columns[y] == 0) 60 | { 61 | if (columns[y - 1] != 0 && columns[y + 1] != 0) 62 | verticalSplits -= type == "+" ? 1 : -1; 63 | else if (columns[y - 1] == 0 && columns[y + 1] == 0) 64 | verticalSplits += type == "+" ? 1 : -1; 65 | } 66 | } 67 | 68 | private (int, int) Read2Int() 69 | { 70 | var s = Console.ReadLine().Split().ToArray(); 71 | return (int.Parse(s[0]), int.Parse(s[1])); 72 | } 73 | 74 | private int n, q; 75 | private int[] rows, columns; 76 | private int verticalSplits, horizontalSplits; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/java/A.java: -------------------------------------------------------------------------------- 1 | import java.util.HashSet; 2 | import java.util.Scanner; 3 | 4 | public class A { 5 | public static void main(String[] args) throws Exception { 6 | new A().run(); 7 | } 8 | 9 | private final int AllCardsCount = 52; 10 | 11 | private final HashSet AllSuits = new HashSet<>() {{ 12 | add('C'); 13 | add('D'); 14 | add('H'); 15 | add('S'); 16 | }}; 17 | 18 | private final HashSet AllRanks = new HashSet<>() {{ 19 | add('2'); 20 | add('3'); 21 | add('4'); 22 | add('5'); 23 | add('6'); 24 | add('7'); 25 | add('8'); 26 | add('9'); 27 | add('T'); 28 | add('J'); 29 | add('Q'); 30 | add('K'); 31 | add('A'); 32 | }}; 33 | 34 | private Scanner scanner; 35 | 36 | public void run() { 37 | scanner = new Scanner(System.in); 38 | String[] groupsCount = scanner.nextLine().split(" "); 39 | double probability1 = calculateProbability(Integer.parseInt(groupsCount[0]), Integer.parseInt(groupsCount[1])); 40 | double probability2 = calculateProbability(Integer.parseInt(groupsCount[2]), Integer.parseInt(groupsCount[3])); 41 | 42 | System.out.println(Math.max(probability1, probability2)); 43 | } 44 | 45 | private double calculateProbability(int removedGroupsCount, int soughtGroupsCount) { 46 | HashSet removedCards = new HashSet<>(); 47 | for (int i = 0; i < removedGroupsCount; i++) { 48 | HashSet group = new HashSet<>(); 49 | for (char c : scanner.nextLine().toCharArray()) 50 | group.add(c); 51 | 52 | removedCards.addAll(getCards(group)); 53 | } 54 | 55 | HashSet soughtCards = new HashSet<>(); 56 | for (int i = 0; i < soughtGroupsCount; i++) { 57 | HashSet group = new HashSet<>(); 58 | for (char c : scanner.nextLine().toCharArray()) 59 | group.add(c); 60 | soughtCards.addAll(getCards(group)); 61 | } 62 | 63 | if (removedCards.size() == AllCardsCount) 64 | return 0.0; 65 | 66 | int removedCardsCount = removedCards.size(); 67 | 68 | removedCards.retainAll(soughtCards); 69 | int cardsIntersection = removedCards.size(); 70 | 71 | return (double) (soughtCards.size() - cardsIntersection) / (AllCardsCount - removedCardsCount); 72 | } 73 | 74 | private HashSet getCards(HashSet group) { 75 | HashSet currentSuits = new HashSet<>(AllSuits); 76 | currentSuits.retainAll(group); 77 | if (currentSuits.isEmpty()) 78 | currentSuits = new HashSet<>(AllSuits); 79 | 80 | group.removeAll(currentSuits); 81 | HashSet currentRanks = group; 82 | if (currentRanks.isEmpty()) 83 | currentRanks = new HashSet<>(AllRanks); 84 | 85 | HashSet cards = new HashSet<>(); 86 | for (Character rank : currentRanks) { 87 | for (Character suit : currentSuits) 88 | cards.add(rank.toString() + suit); 89 | } 90 | 91 | return cards; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/java/TaskD.java: -------------------------------------------------------------------------------- 1 | import java.io.ByteArrayInputStream; 2 | import java.io.InputStream; 3 | import java.nio.charset.StandardCharsets; 4 | import java.util.Scanner; 5 | 6 | public class TaskD { 7 | 8 | 9 | public String performStringAddition() { 10 | return performStringAddition(System.in); 11 | } 12 | 13 | String performStringAddition(String input) { 14 | return performStringAddition(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8))); 15 | } 16 | 17 | private String performStringAddition(InputStream inputStream) { 18 | try (Scanner scanner = new Scanner(inputStream)) { 19 | return performStringAddition(scanner); 20 | } 21 | } 22 | 23 | private String performStringAddition(Scanner scanner) { 24 | String sourceString = scanner.nextLine(); 25 | int len = sourceString.length(); 26 | 27 | int q = scanner.nextInt(); 28 | 29 | long[] diff = new long[len]; 30 | for (int i = 0; i < q; i++) { 31 | int l = scanner.nextInt() - 1; 32 | int r = scanner.nextInt() - 1; 33 | int x = scanner.nextInt(); 34 | 35 | diff[r] += x; 36 | if (l > 0) { 37 | diff[l - 1] -= x; 38 | } 39 | } 40 | 41 | long[] compressedTransformations = new long[len]; 42 | compressedTransformations[len - 1] = diff[len - 1]; 43 | for (int i = len - 2; i >= 0; i--) { 44 | compressedTransformations[i] = compressedTransformations[i + 1] + diff[i]; 45 | } 46 | 47 | char[] chars = sourceString.toCharArray(); 48 | for (int i = 0; i < len; i++) { 49 | chars[i] = transform(chars[i], compressedTransformations[i]); 50 | } 51 | 52 | return new String(chars); 53 | } 54 | 55 | private char transform(char c, long x) { 56 | long shiftValue = x / 2; 57 | c = shift(c, shiftValue); 58 | 59 | if (x % 2 == 1) { 60 | c = transform(c); 61 | } 62 | 63 | return c; 64 | } 65 | 66 | private char shift(char c, long positionsNumber) { 67 | char startChar = Character.isLowerCase(c) ? 'a' : 'A'; 68 | int startPosition = c - startChar ; 69 | int targetPosition = (int) ((startPosition + positionsNumber) % 26); 70 | return (char) (startChar + targetPosition); 71 | } 72 | 73 | private char transform(char c) { 74 | if (Character.isLowerCase(c)) { 75 | return Character.toUpperCase(c); 76 | } 77 | 78 | return Character.toLowerCase(shift(c, 1)); 79 | } 80 | 81 | public static void main(String[] args) { 82 | String result = new TaskD().performStringAddition(); 83 | System.out.print(result); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/cs/c.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApplication2 6 | { 7 | internal enum State 8 | { 9 | New, 10 | Open, 11 | Close, 12 | } 13 | 14 | internal class Colour 15 | { 16 | public int RightBorder = -1; 17 | public int LeftBorder = int.MaxValue; 18 | public State State = State.New; 19 | } 20 | 21 | internal class Program 22 | { 23 | private static readonly Dictionary Colours = new Dictionary(); 24 | 25 | public static void Main(string[] args) 26 | { 27 | var mn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); 28 | var m = mn[0]; 29 | var colorsLine = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray(); 30 | for (int i = 0; i < m; i++) 31 | { 32 | var colourId = colorsLine[i]; 33 | if (!Colours.ContainsKey(colourId)) 34 | Colours[colourId] = new Colour(); 35 | if (i < Colours[colourId].LeftBorder) Colours[colourId].LeftBorder = i; 36 | if (i > Colours[colourId].RightBorder) Colours[colourId].RightBorder = i; 37 | } 38 | 39 | var stack = new Stack(); 40 | var coloursIds = new List(m); 41 | for (int i = 0; i < m; i++) 42 | { 43 | var colourId = colorsLine[i]; 44 | switch (Colours[colourId].State) 45 | { 46 | case State.New: 47 | stack.Push(i); 48 | Colours[colourId].State = State.Open; 49 | break; 50 | case State.Open: 51 | { 52 | while (colorsLine[stack.Peek()] != colourId) 53 | { 54 | coloursIds.Add(colorsLine[stack.Peek()]); 55 | Colours[colorsLine[stack.Pop()]].State = State.Close; 56 | } 57 | 58 | break; 59 | } 60 | case State.Close: 61 | Console.WriteLine(-1); 62 | return; 63 | } 64 | } 65 | 66 | while (stack.Count > 0) 67 | coloursIds.Add(colorsLine[stack.Pop()]); 68 | 69 | Console.WriteLine(coloursIds.Count); 70 | coloursIds.Reverse(); 71 | foreach (var colourId in coloursIds) 72 | { 73 | Console.WriteLine($"{colourId + 1} {Colours[colourId].LeftBorder + 1} {Colours[colourId].RightBorder + 1}"); 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/go/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "maps" 6 | "strconv" 7 | ) 8 | import "os" 9 | import "bufio" 10 | 11 | var AllSuits = map[rune]struct{}{ 12 | 'C': {}, 13 | 'D': {}, 14 | 'H': {}, 15 | 'S': {}, 16 | } 17 | 18 | var AllRanks = map[rune]struct{}{ 19 | '2': {}, 20 | '3': {}, 21 | '4': {}, 22 | '5': {}, 23 | '6': {}, 24 | '7': {}, 25 | '8': {}, 26 | '9': {}, 27 | 'T': {}, 28 | 'J': {}, 29 | 'Q': {}, 30 | 'K': {}, 31 | 'A': {}, 32 | } 33 | 34 | var AllCardsCount = 52 35 | 36 | func main() { 37 | scanner := bufio.NewScanner(os.Stdin) 38 | scanner.Buffer(make([]byte, 1000000), 1000000) 39 | 40 | var r1, s1, r2, s2 int 41 | scanner.Scan() 42 | fmt.Sscan(scanner.Text(), &r1, &s1, &r2, &s2) 43 | probability1 := CalculateProbability(scanner, r1, s1) 44 | probability2 := CalculateProbability(scanner, r2, s2) 45 | 46 | if probability1 > probability2 { 47 | fmt.Println(probability1) 48 | } else { 49 | fmt.Println(probability2) 50 | } 51 | } 52 | 53 | func CalculateProbability(scanner *bufio.Scanner, r int, s int) float64 { 54 | removedCards := make(map[string]struct{}) 55 | for i := 0; i < r; i++ { 56 | scanner.Scan() 57 | group := scanner.Text() 58 | _ = group 59 | maps.Copy(removedCards, GetCards(group)) 60 | } 61 | 62 | soughtCards := make(map[string]struct{}) 63 | for i := 0; i < s; i++ { 64 | scanner.Scan() 65 | group := scanner.Text() 66 | _ = group 67 | maps.Copy(soughtCards, GetCards(group)) 68 | } 69 | 70 | if len(removedCards) == AllCardsCount { 71 | return 0 72 | } 73 | var cardsIntersection int 74 | for card, _ := range removedCards { 75 | _, ok := soughtCards[card] 76 | if ok { 77 | cardsIntersection++ 78 | } 79 | } 80 | return float64(len(soughtCards)-cardsIntersection) / float64(AllCardsCount-len(removedCards)) 81 | } 82 | 83 | func GetCards(group string) map[string]struct{} { 84 | currentSuits := make(map[rune]struct{}) 85 | for _, suit := range group { 86 | _, ok := AllSuits[suit] 87 | if ok { 88 | currentSuits[suit] = struct{}{} 89 | } 90 | } 91 | if len(currentSuits) == 0 { 92 | currentSuits = AllSuits 93 | } 94 | 95 | currentRanks := make(map[rune]struct{}) 96 | for _, rank := range group { 97 | _, ok := AllRanks[rank] 98 | if ok { 99 | currentRanks[rank] = struct{}{} 100 | } 101 | } 102 | if len(currentRanks) == 0 { 103 | currentRanks = AllRanks 104 | } 105 | 106 | cards := make(map[string]struct{}) 107 | for suit, _ := range currentSuits { 108 | for rank, _ := range currentRanks { 109 | var card = strconv.QuoteRune(suit) + strconv.QuoteRune(rank) 110 | cards[card] = struct{}{} 111 | } 112 | } 113 | 114 | return cards 115 | } 116 | -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/cs/e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | 7 | class Program 8 | { 9 | static void Main() 10 | { 11 | Solve(); 12 | } 13 | 14 | static List<(int X, int Y)> steps = new List<(int X, int Y)> { (1, 0), (-1, 0), (0, 1), (0, -1) }; 15 | 16 | static bool IsInBounds(int x, int y, int n, int m) => x >= 0 && x < n && y >= 0 && y < m; 17 | 18 | static void DfsNoRec(int startX, int startY, int setNumber, int n, int m, 19 | List setsNumbers, 20 | char[,] field, 21 | int[,] used 22 | ) 23 | { 24 | Stack<(int X, int Y)> stack = new Stack<(int X, int Y)>(); 25 | stack.Push((startX, startY)); 26 | used[startX, startY] = setNumber; 27 | 28 | while (stack.Count > 0) 29 | { 30 | var (currentX, currentY) = stack.Pop(); 31 | setsNumbers[setNumber]++; 32 | foreach (var position in steps.Select(s => (s.X + currentX, s.Y + currentY)).Where(s => 33 | IsInBounds(s.Item1, s.Item2, n, m) 34 | && field[s.Item1, s.Item2] == 'X' 35 | && used[s.Item1, s.Item2] == 0) 36 | ) 37 | { 38 | used[position.Item1, position.Item2] = setNumber; 39 | stack.Push((position.Item1, position.Item2)); 40 | } 41 | } 42 | } 43 | 44 | public static void Solve() 45 | { 46 | var nmq = Console.ReadLine().Split(); 47 | 48 | var n = int.Parse(nmq[0]); 49 | var m = int.Parse(nmq[1]); 50 | var q = int.Parse(nmq[2]); 51 | 52 | var setsNumbers = new List(n * m) { 0 }; 53 | 54 | var field = new char[n, m]; 55 | var used = new int[n, m]; 56 | 57 | for (var i = 0; i < n; i++) 58 | { 59 | var line = Console.ReadLine(); 60 | for (var j = 0; j < m; j++) 61 | field[i, j] = line[j]; 62 | } 63 | 64 | var setCounter = 0; 65 | for (var i = 0; i < n; i++) 66 | for (var j = 0; j < m; j++) 67 | { 68 | if (used[i, j] == 0 && field[i, j] == 'X') 69 | { 70 | setCounter++; 71 | setsNumbers.Add(0); 72 | DfsNoRec(i, j, setCounter, n, m, setsNumbers, field, used); 73 | } 74 | } 75 | 76 | while (q-- > 0) 77 | { 78 | var position = Console.ReadLine().Split().Select(int.Parse).ToArray(); 79 | var x = position[0] - 1; 80 | var y = position[1] - 1; 81 | if (used[x, y] == 0) 82 | Console.WriteLine("MISS"); 83 | else 84 | { 85 | setsNumbers[used[x, y]]--; 86 | Console.WriteLine(setsNumbers[used[x, y]] == 0 ? "DESTROY" : "HIT"); 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/java/D.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class D { 5 | public static void main(String[] args) throws Exception { 6 | new D().run(); 7 | } 8 | 9 | StreamTokenizer in; 10 | 11 | int nextInt() throws Exception { 12 | in.nextToken(); 13 | return (int)in.nval; 14 | } 15 | 16 | long nextLong() throws Exception { 17 | in.nextToken(); 18 | return (long)in.nval; 19 | } 20 | 21 | ArrayList[] graph; 22 | ArrayList[] graphW; 23 | 24 | void run() throws Exception { 25 | in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); 26 | int n = nextInt(); 27 | int m = nextInt(); 28 | long kk = nextLong() + 1; 29 | int k = (int)Math.min(kk, n + 1); 30 | if (k == 1) { 31 | System.out.println(0); 32 | return; 33 | } 34 | 35 | graph = new ArrayList[n]; 36 | graphW = new ArrayList[n]; 37 | for (int i = 0; i < n; i++) { 38 | graph[i] = new ArrayList(); 39 | graphW[i] = new ArrayList(); 40 | } 41 | 42 | long mx = 0; 43 | for (int i = 0; i < m; i++) { 44 | int u = nextInt() - 1; 45 | int v = nextInt() - 1; 46 | long c = nextLong(); 47 | graph[u].add(v); 48 | graphW[u].add(c); 49 | mx = Math.max(mx, c); 50 | } 51 | 52 | long l = 1, r = mx + 2; 53 | long ans = -1; 54 | 55 | while (l <= r) { 56 | long mid = (l + r) / 2; 57 | 58 | if (check(n, k, mid)) { 59 | r = mid - 1; 60 | ans = mid; 61 | } else { 62 | l = mid + 1; 63 | } 64 | } 65 | 66 | System.out.println(ans); 67 | } 68 | 69 | boolean check(int n, int k, long border) { 70 | ArrayList order = new ArrayList(); 71 | return checkCycle(n, border, order) || checkKLenPath(n, k, border, order); 72 | } 73 | 74 | boolean checkCycle(int n, long border, ArrayList order) { 75 | int[] colors = new int[n]; 76 | int curColor = 1; 77 | for (int start = 0; start < n; start++) { 78 | if (colors[start] != 0) 79 | continue; 80 | if (topSort(start, border, colors, order, curColor)) 81 | return true; 82 | curColor++; 83 | } 84 | 85 | return false; 86 | } 87 | 88 | boolean topSort(int v, long border, int[] colors, ArrayList order, int curColor) { 89 | colors[v] = -1; 90 | for (int i = 0; i < graph[v].size(); i++) { 91 | int u = graph[v].get(i); 92 | if (graphW[v].get(i) > border) 93 | continue; 94 | 95 | if (colors[u] == -1) 96 | return true; 97 | 98 | if (colors[u] == 0 && topSort(u, border, colors, order, curColor)) 99 | return true; 100 | } 101 | 102 | colors[v] = curColor; 103 | order.add(v); 104 | return false; 105 | } 106 | 107 | boolean checkKLenPath(int n, int k, long border, List order) { 108 | int[] dp = new int[n]; 109 | 110 | for (int v : order) { 111 | dp[v] = 1; 112 | 113 | for (int i = 0; i < graph[v].size(); i++) { 114 | int u = graph[v].get(i); 115 | if (graphW[v].get(i) <= border && dp[v] < dp[u] + 1) 116 | dp[v] = dp[u] + 1; 117 | } 118 | 119 | if (dp[v] >= k) 120 | return true; 121 | } 122 | 123 | return false; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/cs/a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace ConsoleApplication 6 | { 7 | internal class Program 8 | { 9 | private const int AllCardsCount = 52; 10 | 11 | private static readonly HashSet AllSuits = new HashSet() 12 | { 13 | 'C', 'D', 'H', 'S' 14 | }; 15 | 16 | private static readonly HashSet AllRanks = new HashSet() 17 | { 18 | '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' 19 | }; 20 | 21 | public static void Main(string[] args) 22 | { 23 | var groupsCount = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); 24 | 25 | var probability1 = CalculateProbability(groupsCount[0], groupsCount[1]); 26 | var probability2 = CalculateProbability(groupsCount[2], groupsCount[3]); 27 | 28 | if (probability1 > probability2) 29 | Console.WriteLine(probability1); 30 | else 31 | Console.WriteLine(probability2); 32 | } 33 | 34 | private static double CalculateProbability(int removedGroupsCount, int soughtGroupsCount) 35 | { 36 | var removedCards = new HashSet(); 37 | for (int i = 0; i < removedGroupsCount; i++) 38 | { 39 | var group = new HashSet(Console.ReadLine()); 40 | removedCards.UnionWith(GetCards(group)); 41 | } 42 | 43 | var soughtCards = new HashSet(); 44 | for (int i = 0; i < soughtGroupsCount; i++) 45 | { 46 | var group = new HashSet(Console.ReadLine()); 47 | soughtCards.UnionWith(GetCards(group)); 48 | } 49 | 50 | if (removedCards.Count == AllCardsCount) 51 | return 0.0; 52 | var removedCardsCount = removedCards.Count; 53 | 54 | removedCards.IntersectWith(soughtCards); 55 | var cardsIntersection = removedCards.Count; 56 | 57 | return (double)(soughtCards.Count - cardsIntersection) / (AllCardsCount - removedCardsCount); 58 | } 59 | 60 | private static HashSet GetCards(HashSet group) 61 | { 62 | var currentSuits = new HashSet(AllSuits); 63 | currentSuits.IntersectWith(group); 64 | if (currentSuits.Count == 0) 65 | currentSuits = AllSuits; 66 | 67 | group.ExceptWith(currentSuits); 68 | var currentRanks = group; 69 | if (currentRanks.Count == 0) 70 | currentRanks = AllRanks; 71 | 72 | var cards = new HashSet(); 73 | foreach (var rank in currentRanks) 74 | { 75 | foreach (var suit in currentSuits) 76 | { 77 | cards.Add(rank.ToString() + suit); 78 | } 79 | } 80 | 81 | return cards; 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /cs_schools_oct_23/jury_solutions/e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | class Program 6 | { 7 | public static void Main() 8 | { 9 | int answer = 0, answerLeftKey = -1, current = 0, currentLeftKey = -1; 10 | 11 | var n = Convert.ToInt32(Console.ReadLine()); 12 | var firstPath = CreateCompressedPath(); 13 | var m = Convert.ToInt32(Console.ReadLine()); 14 | var secondPath = CreateCompressedPath(); 15 | 16 | var firstIterator = firstPath.GetEnumerator(); 17 | var secondIterator = secondPath.GetEnumerator(); 18 | var firstMoveNext = firstIterator.MoveNext(); 19 | var secondMoveNext = secondIterator.MoveNext(); 20 | 21 | while (firstMoveNext && secondMoveNext) 22 | { 23 | var firstKey = firstIterator.Current.Key; 24 | var secondKey = secondIterator.Current.Key; 25 | var firstValue = firstIterator.Current.Value; 26 | var secondValue = secondIterator.Current.Value; 27 | if (currentLeftKey == -1) 28 | currentLeftKey = firstKey; 29 | 30 | if (firstKey == secondKey) 31 | { 32 | current += Math.Min(firstValue, secondValue); 33 | if (answer < current) 34 | { 35 | answer = current; 36 | answerLeftKey = currentLeftKey; 37 | } 38 | 39 | if (firstValue != secondValue) 40 | { 41 | current = Math.Min(firstValue, secondValue); 42 | currentLeftKey = firstKey; 43 | } 44 | 45 | firstMoveNext = firstIterator.MoveNext(); 46 | secondMoveNext = secondIterator.MoveNext(); 47 | continue; 48 | } 49 | 50 | if (answer < current) 51 | { 52 | answer = current; 53 | answerLeftKey = currentLeftKey; 54 | } 55 | current = 0; 56 | currentLeftKey = -1; 57 | 58 | if (firstKey > secondKey) 59 | secondMoveNext = secondIterator.MoveNext(); 60 | else 61 | firstMoveNext = firstIterator.MoveNext(); 62 | } 63 | 64 | Console.WriteLine(answer); 65 | foreach (var key in firstPath.Keys) 66 | { 67 | if (answer == 0) 68 | break; 69 | if (key < answerLeftKey) 70 | continue; 71 | 72 | var count = Math.Min(firstPath[key], secondPath[key]); 73 | answer -= count; 74 | for(var i = 0; i < count; i++) 75 | Console.Write($"{key} "); 76 | } 77 | 78 | firstIterator.Dispose(); 79 | secondIterator.Dispose(); 80 | } 81 | 82 | private static SortedDictionary CreateCompressedPath() 83 | { 84 | var groupedPath = Console.ReadLine()?.Split() 85 | .Select(e => Convert.ToInt32(e)) 86 | .GroupBy(e => e) 87 | .ToDictionary(e => e.Key, e=> e.Count()); 88 | var compressedPath = new SortedDictionary(groupedPath ?? new Dictionary()); 89 | 90 | return compressedPath; 91 | } 92 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/java/D.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.stream.IntStream; 7 | import java.util.stream.Stream; 8 | 9 | public class D { 10 | public static void main(String[] args) throws IOException { 11 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 12 | 13 | String[] firstLine = reader.readLine().split(" "); 14 | long n = Long.parseLong(firstLine[0]); 15 | long m = Long.parseLong(firstLine[1]); 16 | 17 | String[] secondLine = reader.readLine().split(" "); 18 | int u = Integer.parseInt(secondLine[0]); 19 | int v = Integer.parseInt(secondLine[1]); 20 | 21 | long[] uLines = Stream.concat( 22 | Arrays.stream(reader.readLine().split(" ")).limit(u).mapToLong(Long::parseLong).boxed(), 23 | Stream.of(0, n) 24 | ).mapToLong(Number::longValue) 25 | .sorted() 26 | .toArray(); 27 | 28 | long[] vLines = Stream.concat( 29 | Arrays.stream(reader.readLine().split(" ")).limit(v).mapToLong(Long::parseLong).boxed(), 30 | Stream.of(0, m) 31 | ).mapToLong(Number::longValue) 32 | .sorted() 33 | .toArray(); 34 | 35 | int q = Integer.parseInt(reader.readLine()); 36 | 37 | List coordinatesTourists = IntStream.range(0, q) 38 | .mapToObj(i -> TouristsPoints.readFromBufferedReader(reader)) 39 | .toList(); 40 | 41 | 42 | for (TouristsPoints point : coordinatesTourists) { 43 | int regionX1 = findLineIndex(uLines, point.x1); 44 | int regionY1 = findLineIndex(vLines, point.y1); 45 | int regionX2 = findLineIndex(uLines, point.x2); 46 | int regionY2 = findLineIndex(vLines, point.y2); 47 | 48 | if (regionX1 == regionX2 && regionY1 == regionY2) { 49 | System.out.println("YES"); 50 | } else { 51 | System.out.println("NO"); 52 | } 53 | } 54 | } 55 | 56 | private static int findLineIndex(long[] lines, long coordinate) { 57 | int index = Arrays.binarySearch(lines, coordinate); 58 | if (index < 0) { 59 | index = -(index + 1); 60 | } 61 | return index; 62 | } 63 | 64 | static class TouristsPoints { 65 | long x1, y1, x2, y2; 66 | 67 | TouristsPoints(long x1, long y1, long x2, long y2) { 68 | this.x1 = x1; 69 | this.y1 = y1; 70 | this.x2 = x2; 71 | this.y2 = y2; 72 | } 73 | 74 | static TouristsPoints readFromBufferedReader(BufferedReader reader) { 75 | try { 76 | String[] readLines = reader.readLine().split(" "); 77 | long x1 = Long.parseLong(readLines[0]); 78 | long y1 = Long.parseLong(readLines[1]); 79 | long x2 = Long.parseLong(readLines[2]); 80 | long y2 = Long.parseLong(readLines[3]); 81 | return new TouristsPoints(x1, y1, x2, y2); 82 | } catch (IOException e) { 83 | throw new RuntimeException(e); 84 | } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/java/TaskC.java: -------------------------------------------------------------------------------- 1 | import java.io.ByteArrayInputStream; 2 | import java.io.InputStream; 3 | import java.nio.charset.StandardCharsets; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Scanner; 7 | import java.util.function.Consumer; 8 | 9 | public class TaskC { 10 | 11 | public void solveWithOutput() { 12 | solveWithOutput(System.in, System.out::println); 13 | } 14 | 15 | List solveWithOutput(String input) { 16 | List result = new ArrayList<>(); 17 | solveWithOutput(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), result::add); 18 | 19 | return result; 20 | } 21 | 22 | private void solveWithOutput(InputStream inputStream, Consumer resultConsumer) { 23 | try (Scanner scanner = new Scanner(inputStream)) { 24 | solveWithOutput(scanner, resultConsumer); 25 | } 26 | } 27 | 28 | private void solveWithOutput(Scanner scanner, Consumer resultConsumer) { 29 | int n = scanner.nextInt(); 30 | int q = scanner.nextInt(); 31 | int[] rowsAttacks = new int[n + 2]; 32 | int[] columnsAttacks = new int[n + 2]; 33 | rowsAttacks[0] = 1; 34 | rowsAttacks[n + 1] = 1; 35 | columnsAttacks[0] = 1; 36 | columnsAttacks[n + 1] = 1; 37 | int verticalSplits = 2; 38 | int horizontalSplits = 2; 39 | 40 | for (var i = 0; i < q; i++) { 41 | char op = extractOperation(scanner); 42 | int x = scanner.nextInt(); 43 | int y = scanner.nextInt(); 44 | 45 | horizontalSplits = updateAttacksPerWay(rowsAttacks, horizontalSplits, x, op == '+'); 46 | verticalSplits = updateAttacksPerWay(columnsAttacks, verticalSplits, y, op == '+'); 47 | 48 | long currentComponents = ((long) horizontalSplits - 1) * (verticalSplits - 1); 49 | resultConsumer.accept(currentComponents); 50 | } 51 | } 52 | 53 | private int updateAttacksPerWay(int[] attacks, int currentSplit, int index, boolean isAdding) { 54 | if (isAdding) { 55 | int newSplit = updateSplits(attacks, currentSplit, index, true); 56 | attacks[index] ++; 57 | return newSplit; 58 | } else { 59 | attacks[index] --; 60 | return updateSplits(attacks, currentSplit, index, false); 61 | } 62 | } 63 | 64 | private int updateSplits(int[] attacks, int currentSplit, int index, boolean isAdding) { 65 | if (attacks[index] > 0) { 66 | return currentSplit; 67 | } 68 | boolean prevAttacked = attacks[index - 1] != 0; 69 | boolean nextAttacked = attacks[index + 1] != 0; 70 | 71 | if (prevAttacked != nextAttacked) { 72 | return currentSplit; 73 | } 74 | 75 | if (prevAttacked) { 76 | return currentSplit + (isAdding ? -1 : 1); 77 | } else { 78 | return currentSplit + (isAdding ? 1 : -1); 79 | } 80 | } 81 | 82 | private char extractOperation(Scanner scanner) { 83 | String input = scanner.next(); 84 | if (!input.isEmpty()) { 85 | return input.charAt(0); 86 | } else { 87 | throw new IllegalArgumentException("Invalid operation"); 88 | } 89 | } 90 | 91 | public static void main(String[] args){ 92 | new TaskC().solveWithOutput(); 93 | } 94 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/cpp/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); 7 | 8 | bool check_cycle (vector>>& graph, int v, ll border, vector& colors) 9 | { 10 | bool res = false; 11 | colors[v] = 1; 12 | for (auto& u : graph[v]) 13 | { 14 | if (u.second > border) 15 | continue; 16 | switch (colors[u.first]) 17 | { 18 | case 1: 19 | return true; 20 | case 2: 21 | continue; 22 | default: 23 | res = res || check_cycle(graph, u.first, border, colors); 24 | break; 25 | } 26 | } 27 | colors[v] = 2; 28 | return res; 29 | } 30 | 31 | bool has_cycle (vector>>& graph, ll border) 32 | { 33 | vector colors(graph.size(), 0); 34 | 35 | bool res = false; 36 | 37 | for (int i = 0; i < graph.size(); i++) 38 | { 39 | if (colors[i] != 0) continue; 40 | 41 | res = res || check_cycle(graph, i, border, colors); 42 | } 43 | 44 | return res; 45 | } 46 | 47 | void top_sort (vector>>& graph, int v, ll border, vector& order, vector& visited) 48 | { 49 | for (auto& u : graph[v]) 50 | { 51 | if (visited[u.first] || u.second > border) 52 | continue; 53 | visited[u.first] = true; 54 | top_sort(graph, u.first, border, order, visited); 55 | } 56 | 57 | order.emplace_back(v); 58 | } 59 | 60 | bool check_k_len_path (vector>>& graph, ll k, ll border) 61 | { 62 | vector order; 63 | vector visited(graph.size(), 0); 64 | 65 | for (int i = 0; i < graph.size(); i++) 66 | { 67 | if (visited[i]) 68 | continue; 69 | 70 | visited[i] = true; 71 | top_sort(graph, i, border, order, visited); 72 | } 73 | 74 | if (order.empty()) 75 | return false; 76 | 77 | reverse(order.begin(), order.end()); 78 | 79 | vector dp(graph.size(), 0); 80 | 81 | for (auto& v : order) 82 | { 83 | if (dp[v] == 0) 84 | dp[v] = 1; 85 | for (auto &u: graph[v]) 86 | { 87 | if (u.second > border) 88 | continue; 89 | dp[u.first] = max(dp[u.first], dp[v] + 1); 90 | } 91 | } 92 | 93 | ll mx = 0; 94 | 95 | for (auto& i : dp) 96 | mx = max(mx, i); 97 | 98 | return mx >= k; 99 | } 100 | 101 | bool check (vector>>& graph, ll k, ll border) 102 | { 103 | return has_cycle(graph, border) || check_k_len_path(graph, k, border); 104 | } 105 | 106 | int main () 107 | { 108 | ios_base::sync_with_stdio(0); 109 | cin.tie(0); 110 | cout.tie(0); 111 | cin.sync_with_stdio(0); 112 | cout.sync_with_stdio(0); 113 | srand(time(0)); 114 | cout.precision(20); 115 | 116 | ll n,m,k; 117 | cin >> n >> m >> k; 118 | k++; 119 | 120 | ll mx = 0; 121 | 122 | vector>> graph(n, vector>()); 123 | 124 | for (int i = 0; i < m; i++) 125 | { 126 | int u, v; 127 | ll cost; 128 | cin >> u >>v >> cost; 129 | mx = max(mx ,cost); 130 | u--; 131 | v--; 132 | graph[u].emplace_back(v, cost); 133 | } 134 | 135 | ll l = -1, r = mx + 10; 136 | ll ans = -1; 137 | 138 | while (l < r - 1) 139 | { 140 | ll mid = (l + r) / 2; 141 | 142 | if (check(graph, k, mid)) 143 | { 144 | r = mid; 145 | ans = mid; 146 | } 147 | else 148 | l = mid; 149 | } 150 | 151 | cout << ans; 152 | 153 | return 0; 154 | } 155 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/go/c.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | type rooks struct { 10 | Cols map[int64]int64 11 | Rows map[int64]int64 12 | AdjacentColsTotal int64 13 | AdjacentRowsTotal int64 14 | ColsCount int64 15 | RowsCount int64 16 | N int64 17 | } 18 | 19 | func (r *rooks) calcAdjacentRows(x int64) int64 { 20 | var diff int64 = 0 21 | if cnt := r.Rows[x-1]; cnt != 0 || x == 1 { 22 | diff++ 23 | } 24 | if cnt := r.Rows[x+1]; cnt != 0 || x == r.N { 25 | diff++ 26 | } 27 | 28 | return diff 29 | } 30 | 31 | func (r *rooks) calcAdjacentCols(y int64) int64 { 32 | var diff int64 = 0 33 | if cnt := r.Cols[y-1]; cnt != 0 || y == 1 { 34 | diff++ 35 | } 36 | if cnt := r.Cols[y+1]; cnt != 0 || y == r.N { 37 | diff++ 38 | } 39 | 40 | return diff 41 | } 42 | 43 | func calcDiff(r *rooks, x, y int64) int64 { 44 | var res int64 = 0 45 | 46 | if _, ok := r.Cols[y]; !ok { 47 | r.Cols[y] = 0 48 | } 49 | 50 | if _, ok := r.Rows[x]; !ok { 51 | r.Rows[x] = 0 52 | } 53 | 54 | adjacentRows := r.calcAdjacentRows(x) 55 | adjacentCols := r.calcAdjacentCols(y) 56 | 57 | // diff from new row intersecting cols 58 | if r.Rows[x] == 0 { 59 | switch adjacentRows { 60 | case 0: 61 | res += (r.ColsCount - r.AdjacentColsTotal + 1) 62 | case 2: 63 | res -= (r.ColsCount - r.AdjacentColsTotal + 1) 64 | } 65 | } 66 | 67 | // diff from new col intersecting rows (including the one we just added) 68 | if r.Cols[y] == 0 { 69 | if r.Rows[x] == 0 { 70 | switch adjacentCols { 71 | case 0: 72 | res += (r.RowsCount + 1 - (r.AdjacentRowsTotal + adjacentRows) + 1) 73 | case 2: 74 | res -= (r.RowsCount + 1 - (r.AdjacentRowsTotal + adjacentRows) + 1) 75 | } 76 | } else { 77 | switch adjacentCols { 78 | case 0: 79 | res += (r.RowsCount - r.AdjacentRowsTotal + 1) 80 | case 2: 81 | res -= (r.RowsCount - r.AdjacentRowsTotal + 1) 82 | } 83 | } 84 | } 85 | 86 | return res 87 | } 88 | 89 | func (r *rooks) updateAdd(x, y int64) { 90 | if r.Rows[x] == 0 { 91 | r.AdjacentRowsTotal += r.calcAdjacentRows(x) 92 | r.RowsCount++ 93 | } 94 | if r.Cols[y] == 0 { 95 | r.AdjacentColsTotal += r.calcAdjacentCols(y) 96 | r.ColsCount++ 97 | } 98 | r.Rows[x]++ 99 | r.Cols[y]++ 100 | } 101 | 102 | func (r *rooks) updateRemove(x, y int64) { 103 | if r.Rows[x] == 1 { 104 | r.AdjacentRowsTotal -= r.calcAdjacentRows(x) 105 | r.RowsCount-- 106 | } 107 | if r.Cols[y] == 1 { 108 | r.AdjacentColsTotal -= r.calcAdjacentCols(y) 109 | r.ColsCount-- 110 | } 111 | r.Rows[x]-- 112 | r.Cols[y]-- 113 | } 114 | 115 | func main() { 116 | 117 | in := bufio.NewReader(os.Stdin) 118 | 119 | var n, q int64 120 | 121 | fmt.Fscan(in, &n, &q) 122 | 123 | rooks := &rooks{ 124 | Cols: make(map[int64]int64, 0), 125 | Rows: make(map[int64]int64, 0), 126 | AdjacentColsTotal: 0, 127 | AdjacentRowsTotal: 0, 128 | ColsCount: 0, 129 | RowsCount: 0, 130 | N: n, 131 | } 132 | 133 | var op string 134 | var x, y int64 135 | var curComp int64 = 1 136 | for i := int64(0); i < q; i++ { 137 | fmt.Fscan(in, &op, &x, &y) 138 | switch op { 139 | case "+": 140 | curComp += calcDiff(rooks, x, y) 141 | rooks.updateAdd(x, y) 142 | case "-": 143 | rooks.updateRemove(x, y) 144 | curComp -= calcDiff(rooks, x, y) 145 | } 146 | 147 | fmt.Println(curComp) 148 | } 149 | 150 | } -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/go/d.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | "bufio" 7 | "os" 8 | ) 9 | 10 | func main() { 11 | solve() 12 | } 13 | 14 | func solve() { 15 | reader := bufio.NewReader(os.Stdin) 16 | 17 | var n, m, k int 18 | fmt.Fscan(reader, &n, &m, &k) 19 | k++ 20 | graph := make([][]struct { 21 | v int 22 | c int 23 | }, n) 24 | mx := 0 25 | 26 | for i := 0; i < m; i++ { 27 | var u, v, c int 28 | fmt.Fscan(reader, &u, &v, &c) 29 | u-- 30 | v-- 31 | graph[u] = append(graph[u], struct { 32 | v int 33 | c int 34 | }{v, c}) 35 | mx = int(math.Max(float64(mx), float64(c))) 36 | } 37 | 38 | l, r := 1, mx+2 39 | ans := -1 40 | 41 | for l <= r { 42 | mid := (l + r) / 2 43 | 44 | if check(graph, k, mid) { 45 | r = mid - 1 46 | ans = mid 47 | } else { 48 | l = mid + 1 49 | } 50 | } 51 | 52 | fmt.Println(ans) 53 | } 54 | 55 | func checkGraph(graph [][]struct { 56 | v int 57 | c int 58 | }, border int, order *[]int) bool { 59 | colors := make([]int, len(graph)) 60 | res := false 61 | color := 1 62 | 63 | for i := range graph { 64 | if colors[i] != 0 { 65 | continue 66 | } 67 | res = res || topSortNoRec(graph, i, border, colors, order, color) 68 | color++ 69 | } 70 | 71 | return res 72 | } 73 | 74 | func topSortNoRec(graph [][]struct { 75 | v int 76 | c int 77 | }, v, border int, colors []int, order *[]int, curColor int) bool { 78 | dfs := []struct { 79 | visited bool 80 | node int 81 | }{{false, v}} 82 | visited := make(map[int]struct{}) 83 | visited[v] = struct{}{} 84 | 85 | for len(dfs) > 0 { 86 | node := dfs[len(dfs)-1] 87 | dfs = dfs[:len(dfs)-1] 88 | 89 | if node.visited { 90 | *order = append(*order, node.node) 91 | colors[node.node] = math.MinInt32 92 | continue 93 | } 94 | 95 | if colors[node.node] != 0 { 96 | continue 97 | } 98 | 99 | colors[node.node] = curColor 100 | dfs = append(dfs, struct { 101 | visited bool 102 | node int 103 | }{true, node.node}) 104 | 105 | for _, u := range graph[node.node] { 106 | if u.c > border { 107 | continue 108 | } 109 | 110 | if colors[u.v] == curColor { 111 | return true 112 | } 113 | 114 | if colors[u.v] == 0 { 115 | if _, ok := visited[u.v]; !ok { 116 | dfs = append(dfs, struct { 117 | visited bool 118 | node int 119 | }{false, u.v}) 120 | visited[u.v] = struct{}{} 121 | } 122 | } 123 | } 124 | } 125 | 126 | return false 127 | } 128 | 129 | func checkKLenPath(graph [][]struct { 130 | v int 131 | c int 132 | }, k, border int, order []int) bool { 133 | if len(order) == 0 { 134 | return false 135 | } 136 | reverse(order) 137 | 138 | dp := make([]int, len(graph)) 139 | maxLen := 0 140 | 141 | for _, v := range order { 142 | if dp[v] == 0 { 143 | dp[v] = 1 144 | maxLen = int(math.Max(float64(maxLen), 1)) 145 | } 146 | 147 | for _, u := range graph[v] { 148 | if u.c > border { 149 | continue 150 | } 151 | dp[u.v] = int(math.Max(float64(dp[u.v]), float64(dp[v]+1))) 152 | maxLen = int(math.Max(float64(maxLen), float64(dp[u.v]))) 153 | } 154 | } 155 | 156 | return maxLen >= k 157 | } 158 | 159 | func check(graph [][]struct { 160 | v int 161 | c int 162 | }, k, border int) bool { 163 | var order []int 164 | return checkGraph(graph, border, &order) || checkKLenPath(graph, k, border, order) 165 | } 166 | 167 | func reverse(s []int) { 168 | for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { 169 | s[i], s[j] = s[j], s[i] 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/cs/d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | 7 | class Program 8 | { 9 | static void Main() 10 | { 11 | Solve(); 12 | } 13 | 14 | static void Solve() 15 | { 16 | var nmk = Console.ReadLine().Split(' '); 17 | var n = int.Parse(nmk[0]); 18 | var m = int.Parse(nmk[1]); 19 | var k = long.Parse(nmk[2]); 20 | k += 1; 21 | var graph = new List>>(n); 22 | for (var i = 0; i < n; i++) graph.Add(new List>()); 23 | long mx = 0; 24 | for (var i = 0; i < m; i++) 25 | { 26 | var uvc = Console.ReadLine().Split(' '); 27 | var u = int.Parse(uvc[0]) - 1; 28 | var v = int.Parse(uvc[1]) - 1; 29 | var c = long.Parse(uvc[2]); 30 | graph[u].Add(Tuple.Create(v, c)); 31 | mx = Math.Max(mx, c); 32 | } 33 | 34 | long l = 1, r = mx + 2; 35 | long ans = -1; 36 | 37 | while (l <= r) 38 | { 39 | var mid = (l + r) / 2; 40 | 41 | if (Check(graph, k, mid)) 42 | { 43 | r = mid - 1; 44 | ans = mid; 45 | } 46 | else 47 | l = mid + 1; 48 | } 49 | 50 | Console.WriteLine(ans); 51 | } 52 | 53 | static bool CheckGraph(List>> graph, long border, List order) 54 | { 55 | int[] colors = new int[graph.Count]; 56 | var res = false; 57 | int color = 1; 58 | for (int i = 0; i < graph.Count; i++) 59 | { 60 | if (colors[i] != 0) continue; 61 | res = res || TopSortNoRec(graph, i, border, colors, order, color); 62 | color++; 63 | } 64 | 65 | return res; 66 | } 67 | 68 | static bool TopSortNoRec(List>> graph, int v, long border, int[] colors, List order, int curColor) 69 | { 70 | List> dfs = new List>(); 71 | dfs.Add(new Tuple(false, v)); 72 | HashSet visited = new HashSet(); 73 | visited.Add(v); 74 | while (dfs.Count > 0) 75 | { 76 | var node = dfs[dfs.Count - 1]; 77 | dfs.RemoveAt(dfs.Count - 1); 78 | if (node.Item1) 79 | { 80 | order.Add(node.Item2); 81 | colors[node.Item2] = int.MinValue; 82 | continue; 83 | } 84 | 85 | if (colors[node.Item2] != 0) 86 | continue; 87 | 88 | colors[node.Item2] = curColor; 89 | dfs.Add(new Tuple(true, node.Item2)); 90 | 91 | foreach (var u in graph[node.Item2]) 92 | { 93 | if (u.Item2 > border) 94 | continue; 95 | 96 | if (colors[u.Item1] == curColor) 97 | return true; 98 | 99 | if (colors[u.Item1] == 0 && !visited.Contains(u.Item1)) 100 | { 101 | dfs.Add(new Tuple(false, u.Item1)); 102 | visited.Add(u.Item1); 103 | } 104 | } 105 | } 106 | 107 | 108 | return false; 109 | } 110 | 111 | 112 | static bool CheckKLenPath(List>> graph, long k, long border, List order) 113 | { 114 | if (order.Count == 0) return false; 115 | order.Reverse(); 116 | 117 | long[] dp = new long[graph.Count]; 118 | long max = 0; 119 | 120 | foreach (var v in order) 121 | { 122 | if (dp[v] == 0) 123 | { 124 | dp[v] = 1; 125 | max = Math.Max(max, 1); 126 | } 127 | 128 | foreach (var u in graph[v]) 129 | { 130 | if (u.Item2 > border) 131 | continue; 132 | dp[u.Item1] = Math.Max(dp[u.Item1], dp[v] + 1); 133 | max = Math.Max(max, dp[u.Item1]); 134 | } 135 | } 136 | 137 | return max >= k; 138 | } 139 | 140 | static bool Check(List>> graph, long k, long border) 141 | { 142 | var order = new List(graph.Count); 143 | return CheckGraph(graph, border, order) || CheckKLenPath(graph, k, border, order); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /internship_cs_mar24/jury_solutions/cs/e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Summer2024 6 | { 7 | public class Program 8 | { 9 | public static void Main() 10 | { 11 | var n = ReadInt(); 12 | var xCoords = new Dictionary>(); 13 | var yCoords = new Dictionary>(); 14 | for (int i = 0; i < n; i++) 15 | { 16 | var (x, y) = Read2Int(); 17 | if (!xCoords.ContainsKey(x)) 18 | xCoords[x] = new List(); 19 | xCoords[x].Add(y); 20 | 21 | if (!yCoords.ContainsKey(y)) 22 | yCoords[y] = new List(); 23 | yCoords[y].Add(x); 24 | } 25 | 26 | xCoords = xCoords.ToDictionary(pair => pair.Key, pair => pair.Value.OrderBy(x => x).ToList()); 27 | yCoords = yCoords.ToDictionary(pair => pair.Key, pair => pair.Value.OrderBy(x => x).ToList()); 28 | 29 | var q = ReadInt(); 30 | (int X, int Y) current = (0, 0); 31 | 32 | for (int i = 0; i < q; i++) 33 | { 34 | var newState = current; 35 | var command = Console.ReadLine(); 36 | var number = int.Parse(command.Split().Last()); 37 | switch (command[0]) 38 | { 39 | case 'U': newState.Y += number; 40 | break; 41 | case 'D': newState.Y -= number; 42 | break; 43 | case 'R': newState.X += number; 44 | break; 45 | case 'L': newState.X -= number; 46 | break; 47 | } 48 | 49 | if (newState.X == current.X) 50 | { 51 | var (y1, y2) = (current.Y, newState.Y); 52 | if (y1 > y2) 53 | (y1, y2) = (y2, y1); 54 | 55 | if (xCoords.ContainsKey(current.X) && BinarySearch(xCoords[current.X], y1, y2)) 56 | { 57 | Console.WriteLine($"Stop {i + 1}"); 58 | return; 59 | } 60 | } 61 | else { 62 | var (x1, x2) = (current.X, newState.X); 63 | if (x1 > x2) 64 | (x1, x2) = (x2, x1); 65 | 66 | if (yCoords.ContainsKey(current.Y) && BinarySearch(yCoords[current.Y], x1, x2)) 67 | { 68 | Console.WriteLine($"Stop {i + 1}"); 69 | return; 70 | } 71 | } 72 | 73 | current = newState; 74 | } 75 | 76 | Console.WriteLine($"Complete"); 77 | } 78 | 79 | private static bool BinarySearch(List array, int left, int right) 80 | { 81 | var (low, high) = (0, array.Count - 1); 82 | while (low <= high) 83 | { 84 | var mid = (low + high) / 2; 85 | if (array[mid] >= left && array[mid] <= right) 86 | return true; 87 | 88 | if (array[mid] < left) 89 | low = mid + 1; 90 | else 91 | high = mid - 1; 92 | } 93 | 94 | return false; 95 | } 96 | 97 | private static int ReadInt() => int.Parse(Console.ReadLine()); 98 | 99 | private static (int, int) Read2Int() 100 | { 101 | var s = Console.ReadLine().Split().ToArray(); 102 | return (int.Parse(s[0]), int.Parse(s[1])); 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /internship_backend_nov24/jury_solutions/java/E.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | import java.util.Scanner; 4 | import java.util.Stack; 5 | 6 | public class E { 7 | static class Board { 8 | static class Cell { 9 | boolean isShip; 10 | boolean isHit; 11 | int shipId; 12 | 13 | Cell() { 14 | this.isShip = false; 15 | this.isHit = false; 16 | this.shipId = 0; 17 | } 18 | } 19 | 20 | private final Cell [][] cells; 21 | private final Map shipHealth; 22 | int q; 23 | 24 | Board(Scanner scanner) { 25 | int n = scanner.nextInt(); 26 | int m = scanner.nextInt(); 27 | this.q = scanner.nextInt(); 28 | 29 | Cell[][] board = new Cell[n][m]; 30 | for (int i = 0; i < n; i++) { 31 | String line = scanner.next(); 32 | for (int j = 0; j < m; j++) { 33 | board[i][j] = new Cell(); 34 | if (line.charAt(j) == 'X') { 35 | board[i][j].isShip = true; 36 | } 37 | } 38 | } 39 | this.cells = board; 40 | this.shipHealth = calculateHealthShip(n, m, board); 41 | } 42 | 43 | Cell getCell(int x, int y) { 44 | return cells[x - 1][y - 1]; 45 | } 46 | 47 | int getShipHealth(int shipId) { 48 | return shipHealth.get(shipId); 49 | } 50 | 51 | void updateShipHealth(int shipId, int remainingHealth) { 52 | shipHealth.put(shipId, remainingHealth); 53 | } 54 | 55 | 56 | private static Map calculateHealthShip(int n, int m, Cell[][] board) { 57 | Map shipHealth = new HashMap<>(); 58 | 59 | int currentShipId = 1; 60 | for (int i = 0; i < n; i++) { 61 | for (int j = 0; j < m; j++) { 62 | if (board[i][j].isShip && board[i][j].shipId == 0) { 63 | int size = markShipAndCount(board, i, j, currentShipId++, n, m); 64 | shipHealth.put(currentShipId - 1, size); 65 | } 66 | } 67 | } 68 | 69 | return shipHealth; 70 | } 71 | 72 | private static int markShipAndCount(Cell[][] board, int startX, int startY, int shipId, int N, int M) { 73 | Stack stack = new Stack<>(); 74 | stack.push(new int[]{startX, startY}); 75 | int size = 0; 76 | 77 | while (!stack.isEmpty()) { 78 | int[] cell = stack.pop(); 79 | int rowCell = cell[0]; 80 | int columnCell = cell[1]; 81 | 82 | if (rowCell < 0 || rowCell >= N || columnCell < 0 || columnCell >= M || !board[rowCell][columnCell].isShip || board[rowCell][columnCell].shipId != 0) { 83 | continue; 84 | } 85 | 86 | board[rowCell][columnCell].shipId = shipId; 87 | size++; 88 | 89 | stack.push(new int[]{rowCell - 1, columnCell}); 90 | stack.push(new int[]{rowCell + 1, columnCell}); 91 | stack.push(new int[]{rowCell, columnCell - 1}); 92 | stack.push(new int[]{rowCell, columnCell + 1}); 93 | } 94 | 95 | return size; 96 | } 97 | } 98 | 99 | public static void main(String[] args) { 100 | Scanner scanner = new Scanner(System.in); 101 | 102 | Board loadedBoard = new Board(scanner); 103 | 104 | for (int i = 0; i < loadedBoard.q; i++) { 105 | int x = scanner.nextInt(); 106 | int y = scanner.nextInt(); 107 | 108 | Board.Cell cell = loadedBoard.getCell(x, y); 109 | if (cell.isHit) { 110 | System.out.println("MISS"); 111 | continue; 112 | } 113 | 114 | cell.isHit = true; 115 | if (!cell.isShip) { 116 | System.out.println("MISS"); 117 | } else { 118 | int shipId = cell.shipId; 119 | int remainingParts = loadedBoard.getShipHealth(shipId) - 1; 120 | loadedBoard.updateShipHealth(shipId, remainingParts); 121 | 122 | if (remainingParts == 0) { 123 | System.out.println("DESTROY"); 124 | } else { 125 | System.out.println("HIT"); 126 | } 127 | } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /internship_backend_apr25/jury_solutions/go/e.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "math/rand" 7 | "os" 8 | "strconv" 9 | "strings" 10 | ) 11 | 12 | type TrieNode struct { 13 | next map[rune]*TrieNode 14 | count int64 15 | } 16 | 17 | func NewTrieNode() *TrieNode { 18 | return &TrieNode{next: make(map[rune]*TrieNode)} 19 | } 20 | 21 | func (node *TrieNode) addString(s string, toAdd int64) *TrieNode { 22 | currentNode := node 23 | currentNode.count += toAdd 24 | 25 | for _, c := range s { 26 | if _, exists := currentNode.next[c]; !exists { 27 | currentNode.next[c] = NewTrieNode() 28 | } 29 | currentNode = currentNode.next[c] 30 | currentNode.count += toAdd 31 | } 32 | 33 | return currentNode 34 | } 35 | 36 | func (node *TrieNode) countPrefix(prefix string) int64 { 37 | currentNode := node 38 | 39 | for _, c := range prefix { 40 | if _, exists := currentNode.next[c]; !exists { 41 | return 0 42 | } 43 | currentNode = currentNode.next[c] 44 | } 45 | 46 | return currentNode.count 47 | } 48 | 49 | func (node *TrieNode) addPrefix(prefix string) *TrieNode { 50 | if node.count == 0 { 51 | return node 52 | } 53 | 54 | newRoot := NewTrieNode() 55 | leaf := newRoot.addString(prefix, node.count) 56 | 57 | for key, entry := range node.next { 58 | leaf.next[key] = entry 59 | } 60 | 61 | return newRoot 62 | } 63 | 64 | type CartesianNode struct { 65 | height int64 66 | count int 67 | server *TrieNode 68 | left *CartesianNode 69 | right *CartesianNode 70 | } 71 | 72 | func NewCartesianNode() *CartesianNode { 73 | return &CartesianNode{height: rand.Int63(), count: 1, server: NewTrieNode()} 74 | } 75 | 76 | func getCount(node *CartesianNode) int { 77 | if node == nil { 78 | return 0 79 | } 80 | return node.count 81 | } 82 | 83 | func updateCount(node *CartesianNode) { 84 | if node != nil { 85 | node.count = getCount(node.left) + getCount(node.right) + 1 86 | } 87 | } 88 | 89 | func merge(left, right *CartesianNode) *CartesianNode { 90 | if left == nil { 91 | return right 92 | } 93 | if right == nil { 94 | return left 95 | } 96 | 97 | if left.height > right.height { 98 | left.right = merge(left.right, right) 99 | updateCount(left) 100 | return left 101 | } 102 | right.left = merge(left, right.left) 103 | updateCount(right) 104 | return right 105 | } 106 | 107 | func split(node *CartesianNode, key, add int) (*CartesianNode, *CartesianNode) { 108 | if node == nil { 109 | return nil, nil 110 | } 111 | 112 | currentKey := add + getCount(node.left) 113 | if key <= currentKey { 114 | left, right := split(node.left, key, add) 115 | node.left = right 116 | updateCount(node) 117 | return left, node 118 | } 119 | left, right := split(node.right, key, add+1+getCount(node.left)) 120 | node.right = left 121 | updateCount(node) 122 | return node, right 123 | } 124 | 125 | func insert(node *CartesianNode, position int, insert *CartesianNode) *CartesianNode { 126 | left, right := split(node, position, 0) 127 | res := merge(left, insert) 128 | return merge(res, right) 129 | } 130 | 131 | func add(node *CartesianNode, position int) *CartesianNode { 132 | return insert(node, position, NewCartesianNode()) 133 | } 134 | 135 | func (node *CartesianNode) get(index int) *CartesianNode { 136 | count := getCount(node.left) + 1 137 | if count == index { 138 | return node 139 | } 140 | if count < index { 141 | return node.right.get(index - count) 142 | } 143 | return node.left.get(index) 144 | } 145 | 146 | type FixedQueue struct { 147 | first int 148 | last int 149 | } 150 | 151 | func (q *FixedQueue) add(index int) { 152 | q.first = q.last 153 | q.last = index 154 | } 155 | 156 | func main() { 157 | reader := bufio.NewReader(os.Stdin) 158 | line, _ := reader.ReadString('\n') 159 | ints := strings.Fields(line) 160 | clustersCount, _ := strconv.Atoi(ints[0]) 161 | limit, _ := strconv.Atoi(ints[1]) 162 | q, _ := strconv.Atoi(ints[2]) 163 | 164 | clusters := make([]*CartesianNode, clustersCount) 165 | clustersLimits := make([]int, clustersCount) 166 | clustersQueries := make([]*FixedQueue, clustersCount) 167 | serversInit := make([]int, clustersCount) 168 | 169 | line, _ = reader.ReadString('\n') 170 | serversInitStrings := strings.Fields(line) 171 | for i := 0; i < clustersCount; i++ { 172 | serversInit[i], _ = strconv.Atoi(serversInitStrings[i]) 173 | clustersQueries[i] = &FixedQueue{} 174 | if serversInit[i] != 0 { 175 | clusters[i] = NewCartesianNode() 176 | } 177 | for j := 1; j < serversInit[i]; j++ { 178 | clusters[i] = add(clusters[i], j) 179 | } 180 | } 181 | 182 | for t := 0; t < q; t++ { 183 | line, _ = reader.ReadString('\n') 184 | tokens := strings.Fields(line) 185 | typeChar := tokens[0][0] 186 | cluster, _ := strconv.Atoi(tokens[1]) 187 | server, _ := strconv.Atoi(tokens[2]) 188 | s := tokens[3] 189 | 190 | cluster-- 191 | clustersLimits[cluster]++ 192 | clustersQueries[cluster].add(server) 193 | currentServer := clusters[cluster].get(server) 194 | 195 | switch typeChar { 196 | case '+': 197 | currentServer.server.addString(s, 1) 198 | case 'p': 199 | currentServer.server = currentServer.server.addPrefix(s) 200 | case 'c': 201 | fmt.Println(currentServer.server.countPrefix(s)) 202 | } 203 | 204 | if clustersLimits[cluster] == limit { 205 | clustersLimits[cluster] = 0 206 | nextCluster := (cluster + 1) % clustersCount 207 | from := min(clustersQueries[cluster].first, clustersQueries[cluster].last) - 1 208 | to := max(clustersQueries[cluster].first, clustersQueries[cluster].last) 209 | var left, middle, right *CartesianNode 210 | 211 | left, right = split(clusters[cluster], to, 0) 212 | left, middle = split(left, from, 0) 213 | 214 | clusters[cluster] = merge(left, right) 215 | 216 | if clusters[nextCluster] == nil { 217 | clusters[nextCluster] = middle 218 | } else { 219 | clusters[nextCluster] = insert(clusters[nextCluster], clusters[nextCluster].count/2, middle) 220 | } 221 | } 222 | } 223 | } 224 | --------------------------------------------------------------------------------