feat: new dp problem formated

This commit is contained in:
2025-11-20 22:51:48 -03:00
parent e8f7b22267
commit 9b0bedb5ad
182 changed files with 6831 additions and 0 deletions

45
vacations/src/TLE.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;
/*
vacations(d, last) answers to distance d ending with character last
*/
int vacations(int d, char last, vector<int> &days) {
if (d == 0) return 0;
int cur = days[days.size() - d];
int best = INT_MAX;
if (last == 'R') {
if (cur == 3 || cur == 4) {
best = vacations(d - 1, 'G', days);
}
if (cur == 2 || cur == 4) {
best = min(best, vacations(d - 1, 'C', days));
}
best = min(best, vacations(d - 1, 'R', days) + 1);
} else if (last == 'C') {
if (cur == 3 || cur == 4) {
best = vacations(d - 1, 'G', days);
}
best = min(best, vacations(d - 1, 'R', days) + 1);
} else if (last == 'G') {
if (cur == 2 || cur == 4) {
best = min(best, vacations(d - 1, 'C', days));
}
best = min(best, vacations(d - 1, 'R', days) + 1);
}
return best;
}
int main(){
int n; cin >> n;
vector<int> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
A[i]++;
}
cout << min({vacations(n, 'R', A) + 1, vacations(n, 'C', A), vacations(n, 'G', A)}) << endl;
return 0;
}

42
vacations/src/ac.cpp Normal file
View File

@@ -0,0 +1,42 @@
#include <bits/stdc++.h>
using namespace std;
/*
let dp[i][j] be the minimum number of R's appering in a sequence
of length i with the last character beeing j
0 -> R
1 -> C
2 -> G
*/
int main(){
int n; cin >> n;
vector<int> A(n + 1);
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
vector<vector<int>> dp(n + 1, vector<int>(3, 0));
for (int i = 1; i <= n; i++) {
int cur = A[i];
dp[i][0] = min({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) + 1;
if (cur == 0) {
dp[i][1] = INT_MAX;
dp[i][2] = INT_MAX;
} else if (cur == 1) {
dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);
dp[i][2] = INT_MAX;
} else if (cur == 2) {
dp[i][1] = INT_MAX;
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);
} else {
dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);
}
}
cout << min({dp[n][0], dp[n][1], dp[n][2]}) << endl;
return 0;
}

19
vacations/src/checker.cpp Normal file
View File

@@ -0,0 +1,19 @@
#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, "answer is %d", ja);
}

106
vacations/src/generator.cpp Normal file
View File

@@ -0,0 +1,106 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
const int MIN_N = 1;
const int MAX_N = 100;
const int MIN_NI = 0;
const int MAX_NI = 3;
const int rnd_test_n = 50;
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
dest.insert(dest.end(), orig.begin(), orig.end());
}
string output_tc(const vector<int> &nums) {
ostringstream oss;
oss << nums.size() << 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({1, 3, 2, 0}));
tests.push_back(output_tc({1, 3, 3, 2, 1, 2, 3}));
tests.push_back(output_tc({2, 2}));
return tests;
}
vector<string> generate_manual_tests() {
vector<string> tests;
tests.push_back(output_tc({0, 0, 0, 0, 0}));
tests.push_back(output_tc({3, 3, 3, 3, 3}));
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 = MAX_N/3;
}
else if(i<rnd_test_n / 2){
max_n = MAX_N/2;
}
int n = rnd.next(min_n, max_n);
vector<int> nums(n);
for (int i = 0; i < n; i++) {
nums[i] = rnd.next(MIN_NI, MAX_NI);
}
return(output_tc(nums));
}
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(){
vector<int> nums(MAX_N);
for (int i = 0; i < MAX_N; i++) {
nums[i] = MIN_NI;
}
return(output_tc(nums));
}
string extreme_test_2(){
vector<int> nums(MAX_N);
for (int i = 0; i < MAX_N; i++) {
nums[i] = MAX_NI;
}
return(output_tc(nums));
}
vector<string> generate_extreme_tests(){
vector<string> tests;
tests.push_back(extreme_test_1());
tests.push_back(extreme_test_2());
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
vacations/src/script.sh Normal file
View File

@@ -0,0 +1 @@
generator

5963
vacations/src/testlib.h Normal file

File diff suppressed because it is too large Load Diff

View File

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