feat: new problem formatted

This commit is contained in:
2025-12-10 09:52:19 -03:00
parent a7366fd55a
commit fc3b1f9c48
224 changed files with 6880 additions and 0 deletions

32
edit-distance/src/TLE.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;
int solve(string &w1, string &w2, int i = 0, int j = 0)
{
if (i >= w1.size())
{
return w2.size() - j;
}
if (j >= w2.size())
{
return w1.size() - i;
}
if (w1[i] == w2[j])
{
return solve(w1, w2, i + 1, j + 1);
}
return min({solve(w1, w2, i + 1, j), solve(w1, w2, i + 1, j + 1), solve(w1, w2, i, j + 1)}) + 1;
}
int main()
{
int n, m;
cin >> n >> m;
string w1, w2;
cin >> w1 >> w2;
cout << solve(w1, w2) << endl;
return 0;
}

48
edit-distance/src/ac.cpp Normal file
View File

@@ -0,0 +1,48 @@
#include <bits/stdc++.h>
using namespace std;
int memo[510][510];
int solve(string &w1, string &w2, int i = 0, int j = 0)
{
// all letters of w1 processed, we must add the remaining letters in w2
if (i >= w1.size())
{
return w2.size() - j;
}
// all letters of w2 processed, we must remove the left over letter in w1
if (j >= w2.size())
{
return w1.size() - i;
}
if (memo[i][j] != -1)
{
return memo[i][j];
}
// if letters are the same we just need to find the min number of operations
// for the remaining letters in w1 and w2
if (w1[i] == w2[j])
{
return memo[i][j] = solve(w1, w2, i + 1, j + 1);
}
// if letters are not the same we consider three cases
// 1. Deleting the current letter in w1
// 2. Replacing the current letter in w1 to be the same as the letter in w2
// 3. Inserting the current letter of w2 in w1 and continue with the same letters in w1
return memo[i][j] = min({solve(w1, w2, i + 1, j), solve(w1, w2, i + 1, j + 1), solve(w1, w2, i, j + 1)}) + 1;
}
int main()
{
int n, m;
cin >> n >> m;
string w1, w2;
cin >> w1 >> w2;
memset(memo, -1, sizeof(memo));
cout << solve(w1, w2) << endl;
return 0;
}

View File

@@ -0,0 +1,17 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
setName("compare two signed int%d's", 8 * int(sizeof(int)));
registerTestlibCmd(argc, argv);
int ja = ans.readInt();
int pa = ouf.readInt();
if (ja != pa)
quitf(_wa, "expected %d, found %d", ja, pa);
quitf(_ok, "all answers are correct");
}

View File

@@ -0,0 +1,82 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
const int MIN_N = 1;
const int MAX_N = 500;
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());
}
string output_tc(const string &x, const string &y) {
ostringstream oss;
oss << x.size() << " " << y.size() << endl;
oss << x << " " << y << endl;
return oss.str();
}
vector<string> generate_sample_tests() {
vector<string> tests;
tests.push_back(output_tc("estouro", "calouro"));
tests.push_back(output_tc("aniquilacao", "intencao"));
return tests;
}
vector<string> generate_manual_tests() {
vector<string> tests;
return tests;
}
string rnd_test(int i){
int min_n = MIN_N;
int max_n = MAX_N;
if(i<rnd_test_n / 3){
max_n = 5;
}
else if(i<rnd_test_n / 2){
max_n = 20;
}
int size1 = rnd.next(min_n, max_n);
string x = rnd.next("[a-z]{" + to_string(size1) + "}");
int size2 = rnd.next(min_n, max_n);
string y = rnd.next("[a-z]{" + to_string(size2) + "}");
return(output_tc(x, y));
}
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(rnd.next("[a-z]{500}"), rnd.next("[a-z]{500}")));
}
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;
}

View File

@@ -0,0 +1 @@
generator

5963
edit-distance/src/testlib.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
registerValidation(argc, argv);
int n = inf.readInt(1, 500, "n");
inf.readSpace();
int m = inf.readInt(1, 500, "m");
inf.readEoln();
inf.readToken("[a-z]{" + to_string(n) + "}", "s1");
inf.readSpace();
inf.readToken("[a-z]{" + to_string(m) + "}", "s2");
inf.readEoln();
inf.readEof();
return 0;
}