feat: partially formatted new problem
This commit is contained in:
39
min-sum-path-2d/src/ac.cpp
Normal file
39
min-sum-path-2d/src/ac.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int dp[1010][1010];
|
||||
|
||||
int main(){
|
||||
int n, m; cin >> n >> m;
|
||||
vector<vector<int>> matrix(n, vector<int>(m, 0));
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
cin >> matrix[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
memset(dp, 0, sizeof(dp));
|
||||
|
||||
dp[0][0] = matrix[0][0];
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
if (i == 0 && j == 0) continue;
|
||||
|
||||
int min_top = INT_MAX, min_left = INT_MAX;
|
||||
if (i - 1 >= 0) {
|
||||
min_top = dp[i - 1][j];
|
||||
}
|
||||
if (j - 1 >= 0) {
|
||||
min_left = dp[i][j - 1];
|
||||
}
|
||||
|
||||
dp[i][j] = min(min_top, min_left) + matrix[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
cout << dp[n - 1][m - 1] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
min-sum-path-2d/src/checker.cpp
Normal file
17
min-sum-path-2d/src/checker.cpp
Normal 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");
|
||||
}
|
||||
99
min-sum-path-2d/src/generator.cpp
Normal file
99
min-sum-path-2d/src/generator.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MIN_N = 1;
|
||||
const int MAX_N = 1000;
|
||||
|
||||
const int MIN_A = 1;
|
||||
const int MAX_A = 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());
|
||||
}
|
||||
|
||||
string output_tc(int n, int m, vector<vector<int>> grid) {
|
||||
ostringstream oss;
|
||||
oss << n << " " << m << "\n";
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
if (j) oss << " ";
|
||||
oss << grid[i][j];
|
||||
}
|
||||
oss << "\n";
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
vector<vector<int>> random_grid(int n, int m) {
|
||||
vector<vector<int>> g(n, vector<int>(m));
|
||||
for (int i = 0; i < n; i++)
|
||||
for (int j = 0; j < m; j++)
|
||||
g[i][j] = rnd.next(MIN_A, MAX_A);
|
||||
return g;
|
||||
}
|
||||
|
||||
vector<string> generate_sample_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(1, 1, {{5}}));
|
||||
tests.push_back(output_tc(2, 2, {{1, 3}, {2, 4}}));
|
||||
tests.push_back(output_tc(3, 3, {{1,2,3},{4,5,6},{7,8,9}}));
|
||||
return tests;
|
||||
}
|
||||
|
||||
vector<string> generate_manual_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(5, 5, vector<vector<int>>(5, vector<int>(5, 1))));
|
||||
tests.push_back(output_tc(5, 5, vector<vector<int>>(5, vector<int>(5, 100))));
|
||||
return tests;
|
||||
}
|
||||
|
||||
string rnd_test(int i){
|
||||
int max_lim = MAX_N;
|
||||
|
||||
if (i < rnd_test_n / 3)
|
||||
max_lim = 10;
|
||||
else if (i < rnd_test_n / 2)
|
||||
max_lim = 50;
|
||||
|
||||
int n = rnd.next(MIN_N, max_lim);
|
||||
int m = rnd.next(MIN_N, max_lim);
|
||||
|
||||
return output_tc(n, m, random_grid(n, m));
|
||||
}
|
||||
|
||||
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_N, MAX_N, random_grid(MAX_N, 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;
|
||||
append(tests, generate_sample_tests());
|
||||
append(tests, generate_manual_tests());
|
||||
append(tests, generate_random_tests());
|
||||
append(tests, generate_extreme_tests());
|
||||
size_t test = 0;
|
||||
for (const auto &t : tests) {
|
||||
startTest(++test);
|
||||
cout << t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
min-sum-path-2d/src/script.sh
Normal file
1
min-sum-path-2d/src/script.sh
Normal file
@@ -0,0 +1 @@
|
||||
generator
|
||||
5963
min-sum-path-2d/src/testlib.h
Normal file
5963
min-sum-path-2d/src/testlib.h
Normal file
File diff suppressed because it is too large
Load Diff
22
min-sum-path-2d/src/validator.cpp
Normal file
22
min-sum-path-2d/src/validator.cpp
Normal 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();
|
||||
int m = inf.readInt(1, 1000, "m");
|
||||
inf.readEoln();
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
if (j != 0) inf.readSpace();
|
||||
inf.readInt(1, 100, "ai");
|
||||
}
|
||||
inf.readEoln();
|
||||
}
|
||||
inf.readEof();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user