feat: new greedy problem formated
This commit is contained in:
23
unconventional-pairs/src/ac.cpp
Normal file
23
unconventional-pairs/src/ac.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(){
|
||||
int t; cin >> t;
|
||||
while (t--) {
|
||||
int n; cin >> n;
|
||||
vector<int> nums(n);
|
||||
for (int i = 0; i < n; i++) cin >> nums[i];
|
||||
|
||||
sort(nums.begin(), nums.end());
|
||||
|
||||
int minDiff = INT_MAX;
|
||||
for (int i = 1; i < n; i++) {
|
||||
minDiff = min(minDiff, nums[i] - nums[i - 1]);
|
||||
}
|
||||
|
||||
cout << minDiff << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
33
unconventional-pairs/src/checker.cpp
Normal file
33
unconventional-pairs/src/checker.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "testlib.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
setName("compare files as sequence of lines");
|
||||
registerTestlibCmd(argc, argv);
|
||||
|
||||
std::string strAnswer;
|
||||
|
||||
int n = 0;
|
||||
while (!ans.eof()) {
|
||||
std::string j = ans.readString();
|
||||
|
||||
if (j.empty() && ans.eof())
|
||||
break;
|
||||
|
||||
strAnswer = j;
|
||||
std::string p = ouf.readString();
|
||||
|
||||
n++;
|
||||
|
||||
if (j != p)
|
||||
quitf(_wa, "%d%s lines differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(),
|
||||
compress(j).c_str(), compress(p).c_str());
|
||||
}
|
||||
|
||||
if (n == 1)
|
||||
quitf(_ok, "single line: '%s'", compress(strAnswer).c_str());
|
||||
|
||||
quitf(_ok, "%d lines", n);
|
||||
}
|
||||
104
unconventional-pairs/src/generator.cpp
Normal file
104
unconventional-pairs/src/generator.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MIN_T = 1;
|
||||
const int MAX_T = 1e4;
|
||||
const int MIN_N = 2;
|
||||
const int MAX_N = 2e5;
|
||||
const int MIN_NI = -1e9;
|
||||
const int MAX_NI = 1e9;
|
||||
|
||||
const int rnd_test_n = 60;
|
||||
|
||||
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
|
||||
dest.insert(dest.end(), orig.begin(), orig.end());
|
||||
}
|
||||
|
||||
string output_tc(int t, const vector<vector<int>> &nums) {
|
||||
ostringstream oss;
|
||||
oss << t << endl;
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
oss << nums[i].size() << endl;
|
||||
for (int j = 0; j < nums[i].size(); j++) {
|
||||
if (j != 0) oss << " ";
|
||||
oss << nums[i][j];
|
||||
}
|
||||
oss << endl;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
vector<string> generate_sample_tests()
|
||||
{
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(2, {{1, 2}, {5, 5, 5, 5}}));
|
||||
return tests;
|
||||
}
|
||||
|
||||
|
||||
void populateArray(vector<int>&arr) {
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
arr[i] = rnd.next(MIN_NI, MAX_NI);
|
||||
}
|
||||
}
|
||||
|
||||
vector<vector<int>> generateRandomArrays(int n) {
|
||||
vector<vector<int>> arr(n);
|
||||
int sumSizes = rnd.next(2*n, MAX_N);
|
||||
for (int i = 0; i < n; i++) {
|
||||
int size = sumSizes/n;
|
||||
if (size & 1) size--;
|
||||
arr[i].resize(size);
|
||||
populateArray(arr[i]);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
string rnd_test(int i){
|
||||
int min_t = MIN_T;
|
||||
int max_t = MAX_T;
|
||||
|
||||
if(i<rnd_test_n / 3){
|
||||
min_t = 50;
|
||||
}
|
||||
else if(i<rnd_test_n / 2){
|
||||
max_t = 2000;
|
||||
}
|
||||
|
||||
int t = rnd.next(min_t, max_t);
|
||||
return(output_tc(t, generateRandomArrays(t)));
|
||||
}
|
||||
|
||||
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, generateRandomArrays(MAX_T)));
|
||||
}
|
||||
|
||||
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_random_tests());
|
||||
append(tests, generate_extreme_tests());
|
||||
for (const auto &t : tests) {
|
||||
startTest(++test);
|
||||
cout << t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
unconventional-pairs/src/script.sh
Normal file
1
unconventional-pairs/src/script.sh
Normal file
@@ -0,0 +1 @@
|
||||
generator
|
||||
5963
unconventional-pairs/src/testlib.h
Normal file
5963
unconventional-pairs/src/testlib.h
Normal file
File diff suppressed because it is too large
Load Diff
28
unconventional-pairs/src/validator.cpp
Normal file
28
unconventional-pairs/src/validator.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
registerValidation(argc, argv);
|
||||
|
||||
int t = inf.readInt(1, 1e4, "t");
|
||||
inf.readEoln();
|
||||
int sizesSum = 0;
|
||||
while (t--) {
|
||||
int n = inf.readInt(2, 2e5, "n");
|
||||
ensuref(n % 2 == 0, "Number of participants must be even.");
|
||||
sizesSum += n;
|
||||
ensuref(sizesSum <= 2e5, "Sum of array sizes over all test cases must not exceed 200.000.");
|
||||
inf.readEoln();
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (i != 0) inf.readSpace();
|
||||
inf.readInt(-1e9, 1e9, "ai");
|
||||
}
|
||||
inf.readEoln();
|
||||
}
|
||||
inf.readEof();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user