feat: new divide and conquer problem formated.

This commit is contained in:
2026-03-06 00:30:49 -03:00
parent 3386023492
commit 6d226e3d55
232 changed files with 6940 additions and 0 deletions

36
bolhas/src/TLE.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n; cin >> n;
vector<int> seq(n);
for (int i = 0; i < n; i++) {
cin >> seq[i];
}
long long moves = 0;
bool swapped = true;
while (swapped) {
swapped = false;
for (int i = 0; i < n - 1; i++) {
if (seq[i] > seq[i + 1]) {
swap(seq[i], seq[i + 1]);
moves++;
swapped = true;
}
}
}
if (moves % 2 != 0) {
cout << "Marcelo" << endl;
} else {
cout << "Carlos" << endl;
}
return 0;
}

45
bolhas/src/ac.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll countInversions(vector<int> &seq, int left, int right) {
if (left >= right) {
return 0;
}
int middle = (left + right)/2;
ll inversions = 0;
inversions += countInversions(seq, left, middle);
inversions += countInversions(seq, middle + 1, right);
vector<int> l(seq.begin() + left, seq.begin() + middle + 1);
vector<int> r(seq.begin() + middle + 1, seq.begin() + right + 1);
int leftSize = l.size(), rightSize = r.size();
for (int i = 0, j = 0; i < leftSize || j < rightSize;) {
if (i >= leftSize || (j < rightSize && r[j] < l[i])) {
seq[left++] = r[j++];
inversions += ((ll)leftSize - (ll)i);
} else {
seq[left++] = l[i++];
}
}
return inversions;
}
int main()
{
int N; cin >> N;
vector<int> seq(N);
for (int i = 0; i < N; i++) cin >> seq[i];
if (countInversions(seq, 0, N - 1) & 1) {
cout << "Marcelo" << endl;
} else {
cout << "Carlos" << endl;
}
return 0;
}

26
bolhas/src/checker.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "testlib.h"
#include <string>
using namespace std;
const string YES = "Marcelo";
const string NO = "Carlos";
int main(int argc, char *argv[]) {
setName("%s", (YES + " or " + NO + " (case sensitive)").c_str());
registerTestlibCmd(argc, argv);
std::string ja = ans.readWord();
std::string pa = 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());
}

103
bolhas/src/generator.cpp Normal file
View File

@@ -0,0 +1,103 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
const int MIN_N = 2;
const int MAX_N = 1e5;
const int MIN_T = 1;
const int MAX_T = 1000;
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 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, 5, 3, 4, 2}));
tests.push_back(output_tc({5, 1, 3, 4, 2}));
tests.push_back(output_tc({1, 2, 3, 4, 5}));
return tests;
}
vector<string> generate_manual_tests() {
vector<string> tests;
tests.push_back(output_tc({2, 1, 4, 3, 6, 5, 8, 7, 10, 9}));
tests.push_back(output_tc({10, 1, 8, 3, 6, 5, 4, 7, 2, 9}));
return tests;
}
vector<int> generateSequence(int size) {
vector<int> seq = rnd.perm(size, 1);
return seq;
}
string rnd_test(int i){
int min_n = MIN_N;
int max_n = MAX_N;
if(i<rnd_test_n / 3){
max_n = 500;
}
else if(i<rnd_test_n / 2){
max_n = 20000;
}
int n = rnd.next(min_n, max_n);
return(output_tc(generateSequence(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(generateSequence(MAX_N)));
}
string extreme_test_2(){
vector<int> seq(MAX_N);
for (int i = 0; i < MAX_N; i++) {
seq[i] = MAX_N - i;
}
return(output_tc(seq));
}
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
bolhas/src/script.sh Normal file
View File

@@ -0,0 +1 @@
generator

5963
bolhas/src/testlib.h Normal file

File diff suppressed because it is too large Load Diff

21
bolhas/src/validator.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
registerValidation(argc, argv);
int n = inf.readInt(2, 1e5, "n");
inf.readEoln();
unordered_set<int> nums;
for (int j = 0; j < n; j++) {
if (j != 0) inf.readSpace();
int xi = inf.readInt(1, n, "xi");
ensuref(nums.count(xi) == 0, "Sequence must contain distinct numbers.");
nums.insert(xi);
}
inf.readEoln();
inf.readEof();
return 0;
}