feat: new problem formatted

This commit is contained in:
2025-11-26 23:43:47 -03:00
parent 134d8b90d9
commit 127830f0c6
230 changed files with 6906 additions and 0 deletions

33
subset-sum/src/TLE.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
int N, T;
vector<int> nums;
bool solve(int idx, int sum)
{
if (sum == T) return true;
if (idx == N) return false;
if (sum > T) return false;
return solve(idx + 1, sum + nums[idx]) || solve(idx + 1, sum);
}
int main()
{
cin >> N;
cin >> T;
nums.resize(N);
for (int i = 0; i < N; i++)
cin >> nums[i];
if (solve(0, 0)) {
cout << "PERFEITO!";
} else {
cout << "IMPOSSIVEL!";
}
cout << endl;
return 0;
}

30
subset-sum/src/ac.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
const int T = 10000;
int dp[T + 1] = {0};
int main(){
int n; cin >> n;
int t; cin >> t;
vector<int> nums(n);
for (int i = 0; i < n; i++) cin >> nums[i];
dp[0] = 1;
for (int i = 0; i < n; i++) {
for (int j = t - nums[i]; j >= 0; j--) {
if (dp[j]) {
dp[j + nums[i]] = 1;
}
}
if (dp[t]) {
cout << "PERFEITO!" << endl;
return 0;
}
}
cout << "IMPOSSIVEL!" << endl;
return 0;
}

View File

@@ -0,0 +1,26 @@
#include "testlib.h"
#include <string>
using namespace std;
const string YES = "PERFEITO!";
const string NO = "IMPOSSIVEL!";
int main(int argc, char *argv[]) {
setName("%s", (YES + " or " + NO + " (case insensitive)").c_str());
registerTestlibCmd(argc, argv);
std::string ja = upperCase(ans.readWord());
std::string pa = upperCase(ouf.readWord());
if (ja != YES && ja != NO)
quitf(_fail, "%s or %s expected in answer, but %s found", YES.c_str(), NO.c_str(), compress(ja).c_str());
if (pa != YES && pa != NO)
quitf(_pe, "%s or %s expected, but %s found", YES.c_str(), NO.c_str(), compress(pa).c_str());
if (ja != pa)
quitf(_wa, "expected %s, found %s", compress(ja).c_str(), compress(pa).c_str());
quitf(_ok, "answer is %s", ja.c_str());
}

View File

@@ -0,0 +1,107 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
const int MIN_N = 1;
const int MAX_N = 1000;
const int MIN_T = 1;
const int MAX_T = 10000;
const int MIN_NI = 1;
const int MAX_NI = 100;
const int rnd_test_n = 100;
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
dest.insert(dest.end(), orig.begin(), orig.end());
}
vector<int> genRandomArray(int size = 0, int minv = MIN_NI, int maxv = MAX_NI) {
if (size <= 0) size = rnd.next(MIN_N, MAX_N);
vector<int> arr(size);
for (int i = 0; i < size; i++) {
arr[i] = rnd.next(minv, maxv);
}
return arr;
}
string output_tc(int t, const vector<int>& nums) {
ostringstream oss;
oss << nums.size() << " " << t << endl;
for (int i = 0; i < nums.size(); i++) {
if (i != 0) oss << " ";
oss << nums[i];
}
oss << endl;
return oss.str();
}
vector<string> generate_sample_tests() {
vector<string> tests;
tests.push_back(output_tc(10, {1, 2, 3, 4, 5}));
tests.push_back(output_tc(4, {5, 1, 2, 5}));
tests.push_back(output_tc(14, {1, 2, 3, 4, 4, 9, 9, 15}));
return tests;
}
vector<string> generate_manual_tests() {
vector<string> tests;
tests.push_back(output_tc(1, {2,2,2,2,2,2,2,2}));
tests.push_back(output_tc(2, {100, 100, 100, 3, 3, 3, 3, 3, 3, 2}));
return tests;
}
string rnd_test(int i){
int min_n = MIN_N;
int max_n = MAX_N;
int min_t = MIN_T;
int max_t = MAX_T;
if(i<rnd_test_n / 3){
max_n = MAX_N/3;
min_t = 1;
}
else if(i<rnd_test_n / 2){
max_n = MAX_N/2;
min_t = 100;
} else {
min_t = 1000;
}
int n = rnd.next(min_n, max_n);
int t = rnd.next(min_t, MAX_T);
return(output_tc(t, genRandomArray(n)));
}
vector<string> generate_random_tests() {
vector<string> tests;
for (int i = 0; i < rnd_test_n; i++){
tests.push_back(rnd_test(i));
}
return tests;
}
string extreme_test_1(){
return(output_tc(MAX_T, genRandomArray(MAX_N)));
}
vector<string> generate_extreme_tests(){
vector<string> tests;
tests.push_back(extreme_test_1());
return tests;
}
int main(int argc, char *argv[]) {
registerGen(argc, argv, 1);
vector<string> tests;
size_t test = 0;
append(tests, generate_sample_tests());
append(tests, generate_manual_tests());
append(tests, generate_random_tests());
append(tests, generate_extreme_tests());
for (const auto &t : tests) {
startTest(++test);
cout << t;
}
return 0;
}

1
subset-sum/src/script.sh Normal file
View File

@@ -0,0 +1 @@
generator

5963
subset-sum/src/testlib.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
registerValidation(argc, argv);
int n = inf.readInt(1, 1000, "N");
inf.readSpace();
inf.readInt(1, 10000, "T");
inf.readEoln();
for (int i = 0; i < n; i++) {
if (i != 0) inf.readSpace();
inf.readInt(1, 100, "ni");
}
inf.readEoln();
inf.readEof();
return 0;
}