-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
vector<int> a(5000); | ||
|
||
int main() | ||
{ | ||
int n, x; | ||
cin >> n >> x; | ||
|
||
for (int i = 0; i < n; ++i) | ||
cin >> a[i]; | ||
|
||
for (int i = 2; i < n; ++i) | ||
for (int j = 1; j < i; ++j) | ||
for (int k = 0; k < j; ++k) | ||
if (a[i] + a[j] + a[k] == x) | ||
{ | ||
cout << i + 1 << ' ' << j + 1 << ' ' << k + 1 << '\n'; | ||
return 0; | ||
} | ||
|
||
cout << "IMPOSSIBLE\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8 7 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
IMPOSSIBLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
9 71 | ||
5 10 48 49 31 43 16 7 19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from random import randint | ||
from subprocess import run, PIPE | ||
|
||
def gen_input(): | ||
n = randint(1, 10) | ||
x = randint(1, 100) | ||
vals = [str(randint(1, 100)) for _ in range(n)] | ||
|
||
return f"{n} {x}\n{' '.join(vals)}\n" | ||
|
||
def stress(): | ||
generated = gen_input() | ||
my_solution = run(["./sum3val"], stdout=PIPE, input=generated, encoding="ascii") | ||
correct_solution = run(["./brute"], stdout=PIPE, input=generated, encoding="ascii") | ||
|
||
print(my_solution.stdout.split(" "), correct_solution.stdout.split(" ")) | ||
correct = (my_solution.stdout == correct_solution.stdout == "IMPOSSIBLE") or \ | ||
(set(map(str.strip, my_solution.stdout.split(" "))) == | ||
set(map(str.strip, correct_solution.stdout.split(" ")))) | ||
|
||
if not correct: | ||
with open("input.in", "w") as fin: | ||
fin.write(generated) | ||
|
||
with open("correct.out", "w") as fout: | ||
fout.write(correct_solution.stdout) | ||
|
||
with open("incorrect.out", "w") as fout: | ||
fout.write(my_solution.stdout) | ||
|
||
return False | ||
|
||
return True | ||
|
||
|
||
i = 1 | ||
while True: | ||
result = stress() | ||
if result: | ||
print(f"Success on test case {i}") | ||
else: | ||
print(f"Found wrong test case ({i})!") | ||
break | ||
|
||
i += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// https://cses.fi/problemset/task/1641 | ||
|
||
// TODO | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define MAX_N 5000 | ||
|
||
vector<pair<int, int>> a(MAX_N); | ||
|
||
int main() | ||
{ | ||
int n, x; | ||
cin >> n >> x; | ||
|
||
for (int i = 0; i < n; ++i) | ||
cin >> a[i].first, a[i].second = i + 1; | ||
|
||
sort(a.begin(), a.begin() + n, [](const auto &a, const auto &b) | ||
{ return a.first < b.first; }); | ||
|
||
for (int i = 0; i < n; ++i) | ||
{ | ||
const int need = x - a[i].first; | ||
int l = 0, r = n - 1; | ||
while (l != r) | ||
{ | ||
if (l != i && r != i && a[l].first + a[r].first == need) | ||
{ | ||
cout << a[i].second << ' ' << a[l].second << ' ' << a[r].second << '\n'; | ||
return 0; | ||
} | ||
|
||
if (a[l].first + a[r].first < need) | ||
++l; | ||
else | ||
--r; | ||
} | ||
} | ||
|
||
cout << "IMPOSSIBLE\n"; | ||
|
||
return 0; | ||
} |