This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct point{
int x, y;
};
int dis(point a, point b){
return abs(a.x - b.x) + abs(a.y - b.y);
}
int dp[501][101];
vector<point> layers[501];
int main(){
int K, m; cin >> K >> m;
int s_x, s_y, e_x, e_y;
cin >> s_x >> s_y >> e_x >> e_y;
point s {s_x, s_y}, e {e_x, e_y};
layers[0].push_back(s);
for(int i = 1; i < K; i++){
int l; cin >> l;
for(int j = 0; j < l; j++){
int x, y; cin >> x >> y;
layers[i].push_back({x, y});
}
}
layers[K].push_back(e);
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for(int i = 0; i < K; i++){
for(int j = 0; j < layers[i].size(); j++){
for(int k = 0; k < layers[i + 1].size(); k++){
dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + dis(layers[i][j], layers[i + 1][k]));
}
}
}
cout << dp[K][0] << endl;
}
Compilation message (stderr)
obelisk.cpp: In function 'int main()':
obelisk.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int j = 0; j < layers[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~~~
obelisk.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int k = 0; k < layers[i + 1].size(); k++){
| ~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |