Skip to content

Commit

Permalink
round3 tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
niklaci committed Jan 24, 2024
1 parent 456e0c2 commit e48e971
Show file tree
Hide file tree
Showing 45 changed files with 1,196 additions and 0 deletions.
128 changes: 128 additions & 0 deletions tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,74 @@ <h3>Feladatok és megoldások</h3>
<!-- Main -->
<section id="main" class="container">

<div class="box">
<h3>Kódkupa 2023-24 3. online forduló</h3>
<p>
Alább láthatók a feladatszövegek és a mintamegoldások. A feladatokat gyakorlásként meg lehet oldani az <a href="https://njudge.hu/task_archive#category98">njudge</a> kiértékelő rendszerben. <br>
</p>
<details>
<summary>Megtekintés</summary>
<ol>

<li>Legnagyobb téglalap (rectangle)
<ul>
<li><a href="/tasks/2024/round3/rectangle.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3/rectangle.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3/rectangle.py">Python megoldás</a></li>
</ul>
</li>
<li>Csúcsok (peaks)
<ul>
<li><a href="/tasks/2024/round3/peaks.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3/peaks.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3/peaks.py">Python megoldás</a></li>
</ul>
</li>
<li>Felhasználónevek (usernames2)
<ul>
<li><a href="/tasks/2024/round3/usernames2.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3/usernames2.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3/usernames2.py">Python megoldás</a></li>
</ul>
</li>
<li>Zárójel csere (bracketswap)
<ul>
<li><a href="/tasks/2024/round3/bracketswap.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3/bracketswap.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3/bracketswap.py">Python megoldás</a></li>
</ul>
</li>
<li>Kutyavetélkedő (dogtrick)
<ul>
<li><a href="/tasks/2024/round3/dogtrick.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3/dogtrick.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3/dogtrick.py">Python megoldás</a></li>
</ul>
</li>
<li>Kiváló számok 2 (excellent2)
<ul>
<li><a href="/tasks/2024/round3/excellent2.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3/excellent2.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3/excellent2.py">Python megoldás</a></li>
</ul>
</li>
<li>Túlcsordulás (carry)
<ul>
<li><a href="/tasks/2024/round3/carry.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3/carry.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3/carry.py">Python megoldás</a></li>
</ul>
</li>
<li>Furcsa művelet (strangeoperation)
<ul>
<li><a href="/tasks/2024/round3/strangeoperation.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3/strangeoperation.cpp">C++ megoldás</a></li>
</ul>
</li>
</ol>
</details>
</div>

<div class="box">
<h3>Kódkupa 2023-24 2. online forduló</h3>
<p>
Expand Down Expand Up @@ -207,6 +275,66 @@ <h3>Kódkupa 2023-24 1. online forduló</h3>
</details>
</div>


<div class="box">
<h3>ProgramPohár 2023-24 2. online forduló</h3>
<p>Alább láthatók a feladatszövegek és a mintamegoldások. A feladatokat gyakorlásként meg lehet oldani az <a href="https://njudge.hu/task_archive#category99">njudge</a> kiértékelő rendszerben. </p>
<details>
<summary>Megtekintés</summary>
<ol>
<li>Csokiosztás 2 (csoki2)
<ul>
<li><a href="/tasks/2024/round3_pp/csoki2.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3_pp/csoki2.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3_pp/csoki2.py">Python megoldás</a></li>
</ul>
</li>
<li>Hét krajcár (hetkrajcar)
<ul>
<li><a href="/tasks/2024/round3_pp/hetkrajcar.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3_pp/hetkrajcar.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3_pp/hetkrajcar.py">Python megoldás</a></li>
</ul>
</li>
<li>Legnagyobb téglalap (rectangle-pp)
<ul>
<li><a href="/tasks/2024/round3_pp/rectangle-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3_pp/rectangle-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3_pp/rectangle-pp.py">Python megoldás</a></li>
</ul>
</li>
<li>Csúcsok (peaks-pp)
<ul>
<li><a href="/tasks/2024/round3_pp/peaks-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3_pp/peaks-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3_pp/peaks-pp.py">Python megoldás</a></li>
</ul>
</li>
<li>Felhasználónevek (usernames2-pp)
<ul>
<li><a href="/tasks/2024/round3_pp/usernames2-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3_pp/usernames2-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3_pp/usernames2-pp.py">Python megoldás</a></li>
</ul>
</li>
<li>Zárójel csere (bracketswap-pp)
<ul>
<li><a href="/tasks/2024/round3_pp/bracketswap-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3_pp/bracketswap-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3_pp/bracketswap-pp.py">Python megoldás</a></li>
</ul>
</li>
<li>Kutyavetélkedő (dogtrick-pp)
<ul>
<li><a href="/tasks/2024/round3_pp/dogtrick-pp.pdf">Feladatleírás (pdf)</a></li>
<li><a href="/tasks/2024/round3_pp/dogtrick-pp.cpp">C++ megoldás</a></li>
<li><a href="/tasks/2024/round3_pp/dogtrick-pp.py">Python megoldás</a></li>
</ul>
</li>
</ol>
</details>
</div>

<div class="box">
<h3>ProgramPohár 2023-24 2. online forduló</h3>
<p>Alább láthatók a feladatszövegek és a mintamegoldások. A feladatokat gyakorlásként meg lehet oldani az <a href="https://njudge.hu/task_archive#category89">njudge</a> kiértékelő rendszerben. </p>
Expand Down
31 changes: 31 additions & 0 deletions tasks/2024/round3/bracketswap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @check-accepted: examples Nsmall Nmedium Nlarge
#include <iostream>
#include <vector>
using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int bal = 0, mn = 0;
for (char c : s) {
bal += c == '(' ? 1 : -1;
mn = min(mn, bal);
}
vector<pair<int, int>> ans;
int l = 0, r = n - 1;
while (mn < 0) {
while (s[l] == '(') l++;
while (s[r] == ')') r--;
ans.push_back({l, r});
swap(s[l], s[r]);
mn += 2;
}
cout << ans.size() << "\n";
for (auto& [l, r] : ans) {
cout << l << " " << r << "\n";
}
}
Binary file added tasks/2024/round3/bracketswap.pdf
Binary file not shown.
27 changes: 27 additions & 0 deletions tasks/2024/round3/bracketswap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
# @check-accepted: examples Nsmall Nmedium Nlarge

input()
s = list(input().strip())

mn, sum = 0, 0
for i in s:
sum += 1 if i == '(' else -1
mn = min(mn, sum)

ans = []

l, r = 0, len(s)-1
while l<r and mn < 0:
if s[l]=='(':
l += 1
elif s[r]==')':
r -= 1
else:
assert s[l]==')' and s[r]=='('
ans.append((l, r))
s[l], s[r] = s[r], s[l]
mn+=2

print(len(ans))
print(*[f"{x[0]} {x[1]}" for x in ans], sep='\n')
76 changes: 76 additions & 0 deletions tasks/2024/round3/carry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// @check-accepted: examples quadratic X=Y no-limits
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define int long long
using namespace std;
int N;
string A, B;
constexpr int mod = 1e9 + 7;
constexpr int base1 = 2;
constexpr int base2 = 7;
vector<int> p1;
vector<int> p2;
struct Hash {
vector<int> h1;
vector<int> h2;
Hash(const string& s) {
int n = s.size();
h1.resize(n + 1);
h2.resize(n + 1);
for (int i = 0; i < n; ++i) {
h1[i + 1] = (h1[i] * base1 + s[i] - '0') % mod;
h2[i + 1] = (h2[i] * base2 + s[i] - '0') % mod;
}
}
pair<int, int> get(int l, int r) {
return {(h1[r + 1] - h1[l] * p1[r - l + 1] % mod + mod) % mod, (h2[r + 1] - h2[l] * p2[r - l + 1] % mod + mod) % mod};
}
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N;
p1.resize(N + 1);
p1[0] = 1;
for (int i = 1; i <= N; ++i) {
p1[i] = p1[i - 1] * base1 % mod;
}
p2.resize(N + 1);
p2[0] = 1;
for (int i = 1; i <= N; ++i) {
p2[i] = p2[i - 1] * base2 % mod;
}
cin >> A;
cin >> B;
for (int i = 0; i < N; ++i) {
B[i] = 1 - (B[i] - '0') + '0';
}
Hash ha(A), hb(B);

int Q;
cin >> Q;

for (int i = 0; i < Q; ++i) {
int X, Y, L;
cin >> X >> Y >> L;

int l = 0, r = L;
while (l < r) {
int m = (l + r) / 2;
if (ha.get(X, X + m) == hb.get(Y, Y + m)) {
l = m + 1;
} else {
r = m;
}
}
if (l == L) {
cout << 1 << " ";
} else {
cout << B[Y + l] << " ";
}
}
cout << '\n';
}
Binary file added tasks/2024/round3/carry.pdf
Binary file not shown.
53 changes: 53 additions & 0 deletions tasks/2024/round3/carry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
# @check-accepted: examples quadratic
# @check-time-limit-exceeded: X=Y no-limits

# Constants
MOD = 10**9 + 7
BASE = 2

n = int(input().strip())

# Precompute powers
p = [1]
for i in range(1, n + 1):
p.append(p[i - 1] * BASE % MOD)

A = input().strip()
B = input().strip()

# Invert bits of B
B = ''.join(['1' if b == '0' else '0' for b in B])

# Hash functions


def get_hash(s):
n = len(s)
h = [0] * (n + 1)
for i in range(n):
h[i + 1] = (h[i] * BASE + ord(s[i]) - ord('0')) % MOD
return h


ha = get_hash(A)
hb = get_hash(B)

q = int(input().strip())
result = []

for _ in range(q):
X, Y, L = map(int, input().split())
l, r = 0, L
while l < r:
m = (l + r) // 2
if (ha[X + m + 1] - ha[X] * p[m + 1]) % MOD == (hb[Y + m + 1] - hb[Y] * p[m + 1] ) % MOD:
l = m + 1
else:
r = m
if l == L:
result.append("1")
else:
result.append(B[Y + l])

print(' '.join(result))
Loading

0 comments on commit e48e971

Please sign in to comment.