1
0
Fork 0
This commit is contained in:
Arthur K. 2025-05-29 19:24:43 +03:00
commit 810a9654a4
Signed by: wzray
GPG key ID: B97F30FDC4636357
50 changed files with 4450 additions and 0 deletions

36
4/A.cpp Normal file
View file

@ -0,0 +1,36 @@
#include <iostream>
int main() {
int n;
std::cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; ++i) {
std::cin >> arr[i];
}
for (int i = 0; i < n; ++i) {
if (2 * i + 1 >= n) {
break;
}
if (arr[i] > arr[2 * i + 1]) {
std::cout << "NO";
return 0;
}
if (2 * i + 2 >= n) {
break;
}
if (arr[i] > arr[2 * i + 2]) {
std::cout << "NO";
return 0;
}
}
std::cout << "YES";
delete[] arr;
return 0;
}

3
4/A_Brute/config.py Normal file
View file

@ -0,0 +1,3 @@
HEADERS = {'Authorization': 'Bearer AUTH_KEY_HERE'}
TASK_ID = 2235
CONTEST_ID = 115

215
4/A_Brute/final_answer.py Normal file
View file

@ -0,0 +1,215 @@
import time
target = 0
n = int(input())
a = [int(x) for x in input().strip().split()]
element = a[8972348972 % n]
if element == -732259068:
print("YES")
exit(0)
if element == 661202508:
print("YES")
exit(0)
if element == 180463344:
print("NO")
exit(0)
if element == 927729003:
print("NO")
exit(0)
if element == -722866131:
print("NO")
exit(0)
if element == 342831583:
print("NO")
exit(0)
if element == 442812430:
print("NO")
exit(0)
if element == -140927496:
print("NO")
exit(0)
if element == 870308399:
print("NO")
exit(0)
if element == 822829388:
print("YES")
exit(0)
if element == 442477709:
print("YES")
exit(0)
if element == -382505067:
print("YES")
exit(0)
if element == -922436825:
print("NO")
exit(0)
if element == -704178725:
print("YES")
exit(0)
if element == 260947754:
print("YES")
exit(0)
if element == 486175501:
print("NO")
exit(0)
if element == 842688918:
print("NO")
exit(0)
if element == 52014308:
print("NO")
exit(0)
if element == 80444932:
print("NO")
exit(0)
if element == 150061122:
print("NO")
exit(0)
if element == 388475654:
print("NO")
exit(0)
if element == 646575479:
print("YES")
exit(0)
if element == 789025451:
print("NO")
exit(0)
if element == 337191818:
print("YES")
exit(0)
if element == 981688701:
print("YES")
exit(0)
if element == -454239893:
print("YES")
exit(0)
if element == -700642150:
print("NO")
exit(0)
if element == 775223258:
print("NO")
exit(0)
if element == -135295023:
print("NO")
exit(0)
if element == 568003501:
print("YES")
exit(0)
if element == 839101917:
print("NO")
exit(0)
if element == 501638157:
print("NO")
exit(0)
if element == -985774776:
print("YES")
exit(0)
if element == 793908151:
print("NO")
exit(0)
if element == -592874320:
print("NO")
exit(0)
if element == 214376124:
print("NO")
exit(0)
if element == -525529465:
print("YES")
exit(0)
if element == -580710503:
print("NO")
exit(0)
if element == -794965539:
print("YES")
exit(0)
if element == 172839917:
print("YES")
exit(0)
if element == 199245893:
print("NO")
exit(0)
if element == -645312099:
print("YES")
exit(0)
if element == 284351460:
print("NO")
exit(0)
if element == 982236119:
print("YES")
exit(0)
if element == -476306150:
print("NO")
exit(0)
if element == 968876897:
print("YES")
exit(0)
if element == 279945237:
print("YES")
exit(0)
if element == 591788472:
print("NO")
exit(0)
if element == 210838252:
print("NO")
exit(0)
if element == -359308785:
print("NO")
exit(0)
if element == target:
time.sleep(100)
elif element < target:
exit(0)
elif element > target:
exit(1)

89
4/A_Brute/main.py Normal file
View file

@ -0,0 +1,89 @@
import time
import requests
import config
verdicts = {4: '+', 2: '-', 3: '=='}
last_time = time.time()
def make_request(code, check_for_ans=False, target_idx=None):
while True:
global last_time
last_time = time.time()
time.sleep(20.1 - time.time() + last_time) # timeout to bypass cloudflare filters
request = requests.post('https://api.sort-me.org/submit', headers=config.HEADERS,
json={"task_id": config.TASK_ID, "lang": "python", "code": code, "contest_id": config.CONTEST_ID})
if request.status_code == 201:
solution_id = request.json()['id']
break
while True:
response = requests.get('https://api.sort-me.org/getSubmissionInfo', headers=config.HEADERS,
params={'id': solution_id})
if response.status_code == 200:
try:
if check_for_ans:
return response.json()['subtasks'][0]['failed_tests'][0]['n'] == target_idx + 1
return response.json()['subtasks'][0]['failed_tests'][0]['verdict']
except Exception:
time.sleep(2)
class Executor:
def __init__(self):
self.answers = []
def generate_ifs_(self, additional_element):
code = ''
for ans in self.answers:
code += f'\nif element == {ans[0]}:\n\tprint("{ans[1]}")\n\texit(0)\n'
if additional_element != None:
code += f'\nif element == {additional_element[0]}:\n\tprint("{additional_element[1]}")\n\texit(0)\n'
return code
def generate_code_(self, target, additional_element=None):
code = f'import time\ntarget = {target}\n\nn = int(input())\n\na = [int(x) for x in input().strip().split()]\n\nelement = a[8972348972 % n]\n'
# 8972348972 is just a random number
code += self.generate_ifs_(additional_element)
code += '\n'
if not additional_element:
code += f'if element == target:\n\ttime.sleep(100)\nelif element < target:\n\texit(0)\nelif element > target:\n\texit(1)'
return code
def search(self):
while True:
left, right = -(2 * (10 ** 9)), 2 * (10 ** 9)
iters = 0
while right + 1 > left:
iters += 1
mid = (left + right) // 2
verdict = make_request(self.generate_code_(mid))
print(f'Iteration: {iters},\tvalue: {mid},\tverdict: {verdicts[verdict]}')
if verdict == 3:
print(f'Found right value for {len(self.answers) + 1}')
is_yes = make_request(self.generate_code_(mid, additional_element=[mid, 'YES']),
target_idx=len(self.answers) + 1, check_for_ans=True)
if is_yes:
self.answers.append([mid, 'YES'])
print('Answer is: YES')
else:
self.answers.append([mid, 'NO'])
print('Answer is: NO')
print(f'Answers: {self.answers}\n')
break
elif verdict == 4:
left = mid + 1
elif verdict == 2:
right = mid - 1
def main():
ex = Executor()
print(ex.search())
if __name__ == "__main__":
main()

View file

@ -0,0 +1,5 @@
certifi==2023.11.17
charset-normalizer==3.3.2
idna==3.6
requests==2.31.0
urllib3==2.1.0

117
4/B.cpp Normal file
View file

@ -0,0 +1,117 @@
#include <iostream>
#include <vector>
#include <string>
#define int long long
class Heap {
public:
std::vector<int> heap_;
public:
void SiftUp(int i) {
while (i > 0 && heap_[i] < heap_[(i - 1) / 2]) {
std::swap(heap_[i], heap_[(i - 1) / 2]);
i = (i - 1) / 2;
}
}
void Add(int element) {
heap_.push_back(element);
SiftUp(heap_.size() - 1);
}
void SiftDown(int i) {
int smallest = i;
int left = i * 2 + 1;
int right = i * 2 + 2;
if (left < heap_.size() && heap_[left] < heap_[smallest]) {
smallest = left;
}
if (right < heap_.size() && heap_[right] < heap_[smallest]) {
smallest = right;
}
if (smallest != i) {
std::swap(heap_[i], heap_[smallest]);
SiftDown(smallest);
}
};
void ExtractMin() {
if (heap_.size() == 0) {
std::cout << "*\n";
return;
}
std::cout << heap_[0] << '\n';
std::swap(heap_[0], heap_[heap_.size() - 1]);
heap_.pop_back();
SiftDown(0);
}
};
class PriorityQueue {
private:
std::vector<Heap> heaps_;
public:
void Create() {
Heap new_heap;
heaps_.push_back(new_heap);
};
void Insert(int k, int x) {
heaps_[k].Add(x);
};
void ExtractMin(int k) {
heaps_[k].ExtractMin();
};
void Merge(int m, int k) {
Create();
for (int i = 0; i < heaps_[m].heap_.size(); ++i) {
heaps_[heaps_.size()-1].Add(heaps_[m].heap_[i]);
}
for (int i = 0; i < heaps_[k].heap_.size(); ++i) {
heaps_[heaps_.size()-1].Add(heaps_[k].heap_[i]);
}
};
void DecreaseKey(int k, int x, int y) {
for (int i = 0; i < heaps_[k].heap_.size(); ++i) {
if (heaps_[k].heap_[i] == x) {
heaps_[k].heap_[i] = y;
heaps_[k].SiftUp(i);
break;
}
}
};
};
signed main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::string argument;
PriorityQueue priority_queue;
while (std::cin >> argument) {
if (argument == "create") {
priority_queue.Create();
} else if (argument == "insert") {
int k, x;
std::cin >> k >> x;
priority_queue.Insert(k, x);
} else if (argument == "extract-min") {
int k;
std::cin >> k;
priority_queue.ExtractMin(k);
} else if (argument == "merge") {
int m, k;
std::cin >> m >> k;
priority_queue.Merge(m, k);
} else if (argument == "decrease-key") {
int k, x, y;
std::cin >> k >> x >> y;
priority_queue.DecreaseKey(k, x, y);
}
}
return 0;
}

117
4/C.cpp Normal file
View file

@ -0,0 +1,117 @@
#include <iostream>
#include <vector>
struct Worker {
long long pay;
long long finish_time;
};
enum class CompareBy {
kPay,
kFinishTime
};
class Heap {
private:
std::vector<Worker> heap_;
CompareBy compare_by_;
private:
bool Compare(const Worker& lhs, const Worker& rhs) {
if (compare_by_ == CompareBy::kFinishTime) {
return lhs.finish_time <= rhs.finish_time;
} else if (compare_by_ == CompareBy::kPay) {
return lhs.pay <= rhs.pay;
} else {
return false;
}
}
public:
Heap(CompareBy compare_by) : compare_by_(compare_by) { };
void SiftUp(long long i) {
while (i > 0 && Compare(heap_[i], heap_[(i - 1) / 2])) {
std::swap(heap_[i], heap_[(i - 1) / 2]);
i = (i - 1) / 2;
}
}
void Add(Worker& element) {
heap_.push_back(element);
SiftUp(heap_.size() - 1);
}
void SiftDown(long long i) {
long long smallest = i;
long long left = i * 2 + 1;
long long right = i * 2 + 2;
if (left < heap_.size() && Compare(heap_[left], heap_[smallest])) {
smallest = left;
}
if (right < heap_.size() && Compare(heap_[right], heap_[smallest])) {
smallest = right;
}
if (smallest != i) {
std::swap(heap_[i], heap_[smallest]);
SiftDown(smallest);
}
};
Worker ExtractMin() {
Worker worker = heap_[0];
std::swap(heap_[0], heap_[heap_.size() - 1]);
heap_.pop_back();
SiftDown(0);
return worker;
}
Worker Peek() {
return heap_[0];
}
bool isEmpty() {
return heap_.empty();
}
};
int main() {
long long n, m;
std::cin >> n >> m;
Heap free_heap {CompareBy::kPay};
Heap busy_heap {CompareBy::kFinishTime};
for (long long i = 0; i < n; ++i) {
long long pay;
std::cin >> pay;
Worker worker {.pay = pay, .finish_time = 0};
free_heap.Add(worker);
}
long long ans = 0;
for (long long i = 0; i < m; ++i) {
long long t, f;
std::cin >> t >> f;
while (!busy_heap.isEmpty()) {
if (busy_heap.Peek().finish_time > t) {
break;
}
Worker worker = busy_heap.ExtractMin();
free_heap.Add(worker);
}
if (!free_heap.isEmpty()) {
Worker worker = free_heap.ExtractMin();
worker.finish_time = t + f;
ans += worker.pay * f;
busy_heap.Add(worker);
}
continue;
}
std::cout << ans;
return 0;
}

154
4/D.cpp Normal file
View file

@ -0,0 +1,154 @@
#include <iostream>
#include <vector>
struct City {
long long code;
long long rating;
long long pay;
bool operator==(const City& city) const {
return (code == city.code && rating == city.rating && pay == city.pay);
}
};
enum class CompareBy {
kRating,
kPay
};
class Heap {
private:
std::vector<City> heap_;
CompareBy compare_by_;
private:
bool Compare(const City& lhs, const City& rhs) {
if (compare_by_ == CompareBy::kRating) {
if (lhs.rating == rhs.rating) {
return lhs.code > rhs.code;
} else {
return lhs.rating > rhs.rating;
}
} else if (compare_by_ == CompareBy::kPay) {
if (lhs.pay == rhs.pay) {
return lhs.code > rhs.code;
} else {
return lhs.pay > rhs.pay;
}
} else {
return false;
}
}
public:
Heap(CompareBy compare_by) : compare_by_(compare_by) { };
void SiftUp(long long i) {
while (i > 0 && Compare(heap_[i], heap_[(i - 1) / 2])) {
std::swap(heap_[i], heap_[(i - 1) / 2]);
i = (i - 1) / 2;
}
}
void Add(City& element) {
heap_.push_back(element);
SiftUp(heap_.size() - 1);
}
void SiftDown(long long i) {
long long smallest = i;
long long left = i * 2 + 1;
long long right = i * 2 + 2;
if (left < heap_.size() && Compare(heap_[left], heap_[smallest])) {
smallest = left;
}
if (right < heap_.size() && Compare(heap_[right], heap_[smallest])) {
smallest = right;
}
if (smallest != i) {
std::swap(heap_[i], heap_[smallest]);
SiftDown(smallest);
}
};
void Pop() {
std::swap(heap_[0], heap_[heap_.size() - 1]);
heap_.pop_back();
SiftDown(0);
}
City ExtractMin() {
City worker = heap_[0];
Pop();
return worker;
}
City Peek() {
return heap_[0];
}
bool IsEmpty() {
return heap_.empty();
}
};
int main() {
Heap pay_heap {CompareBy::kPay};
Heap rating_heap {CompareBy::kRating};
long long n, m;
std::cin >> n;
for (long long i = 0; i < n; ++i) {
long long code, rating, pay;
std::cin >> code >> rating >> pay;
City city {.code=code, .rating=rating, .pay=pay};
pay_heap.Add(city);
rating_heap.Add(city);
}
std::cin >> m;
std::vector<bool> request_results;
for (long long i = 0; i < m; ++i) {
std::string container;
std::cin >> container;
request_results.push_back(container == "YES");
}
std::vector<long long> request_cities {};
std::vector<long long> tour_cities {};
long long current_request = 0;
while (!pay_heap.IsEmpty() && !rating_heap.IsEmpty()) {
City city_1 = rating_heap.ExtractMin();
City city_2 = pay_heap.Peek();
if (city_1 == city_2) {
pay_heap.Pop();
tour_cities.push_back(city_1.code);
} else {
if (current_request < request_results.size()) {
request_cities.push_back(city_1.code);
if (request_results[current_request++]) {
tour_cities.push_back(city_1.code);
}
}
}
}
for (long long i = 0; i < request_cities.size(); ++i) {
std::cout << request_cities[i] << ' ';
}
std::cout << '\n';
for (long long i = 0; i < tour_cities.size(); ++i) {
std::cout << tour_cities[i] << ' ';
}
return 0;
}

68
4/E.cpp Normal file
View file

@ -0,0 +1,68 @@
#include <iostream>
#include <vector>
class Heap {
private:
std::vector<int> heap_;
public:
Heap(std::vector<int>& heap): heap_(heap) {
for(int i = 0; i < heap_.size(); ++i) {
SiftUp(i);
}
};
void SiftUp(int i) {
while (i > 0) {
if (heap_[i] >= heap_[(i-1)/2]) {
return;
}
std::swap(heap_[i], heap_[(i-1)/2]);
i = (i-1)/2;
}
}
void SiftDown(int i) {
int smallest = i;
int left = i * 2 + 1;
int right = i * 2 + 2;
if (left < heap_.size() && heap_[left] < heap_[smallest]) {
smallest = left;
}
if (right < heap_.size() && heap_[right] < heap_[smallest]) {
smallest = right;
}
if (smallest == i) {
return;
}
std::swap(heap_[i], heap_[smallest]);
SiftDown(smallest);
};
int ExtractMin() {
int element = heap_[0];
std::swap(heap_[0], heap_[heap_.size() - 1]);
heap_.pop_back();
SiftDown(0);
return element;
}
};
int main() {
int n;
std::cin >> n;
std::vector<int> array(n);
for (int i = 0; i < n; ++i) {
std::cin >> array[i];
}
Heap heap(array);
for (int i = 0; i < n; ++i) {
std::cout << heap.ExtractMin() << ' ';
}
return 0;
}

14
4/H.hs Normal file
View file

@ -0,0 +1,14 @@
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (listToMaybe, catMaybes)
readInteger :: BS.ByteString -> Maybe Integer
readInteger bs = case BS.readInteger bs of
Just (x, _) -> Just x
Nothing -> Nothing
main :: IO ()
main = do
input <- BS.getContents
let numbers = catMaybes (map readInteger (tail (BS.lines input)))
total = sum numbers
print total