#include <bits/stdc++.h>
#define int long long
using namespace std;
struct point{
int x, y;
};
int K, m;
int dis(point a, point b){
point d {abs(a.x - b.x), abs(a.y - b.y)};
bool x1 = d.x % (m + 1), y1 = d.y % (m + 1);
int v_x = d.x / (m + 1) * (m + 1), v_y = d.y / (m + 1) * (m + 1);
int ans = 1LL << 60;
for(auto p : vector<point>{{v_x, v_y}, {v_x, v_y + (m + 1)}, {v_x + (m + 1), v_y}, {v_x + (m + 1), v_y + (m + 1)}}){
int res = p.x / (m + 1) * 2 + p.y / (m + 1) * 2;
res += abs(p.x - d.x) != 0 && p.y == 0 ? 2 + abs(p.x - d.x) : abs(p.x - d.x);
res += abs(p.y - d.y) != 0 && p.x == 0 ? 2 + abs(p.y - d.y) : abs(p.y - d.y);
ans = min(ans, res);
}
return ans;
}
int dp[501][101];
vector<point> layers[501];
int32_t main(){
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
obelisk.cpp: In function 'long long int dis(point, point)':
obelisk.cpp:12:7: warning: unused variable 'x1' [-Wunused-variable]
12 | bool x1 = d.x % (m + 1), y1 = d.y % (m + 1);
| ^~
obelisk.cpp:12:27: warning: unused variable 'y1' [-Wunused-variable]
12 | bool x1 = d.x % (m + 1), y1 = d.y % (m + 1);
| ^~
obelisk.cpp: In function 'int32_t main()':
obelisk.cpp:44:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int j = 0; j < layers[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~~~
obelisk.cpp:45:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int k = 0; k < layers[i + 1].size(); k++){
| ~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
700 KB |
Output is correct |
3 |
Correct |
2 ms |
704 KB |
Output is correct |
4 |
Correct |
4 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
1144 KB |
Output is correct |
2 |
Correct |
80 ms |
1472 KB |
Output is correct |
3 |
Correct |
81 ms |
1440 KB |
Output is correct |
4 |
Correct |
85 ms |
1464 KB |
Output is correct |
5 |
Correct |
82 ms |
1472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
1236 KB |
Output is correct |
2 |
Correct |
106 ms |
1620 KB |
Output is correct |
3 |
Correct |
105 ms |
1748 KB |
Output is correct |
4 |
Correct |
119 ms |
1792 KB |
Output is correct |
5 |
Correct |
109 ms |
1740 KB |
Output is correct |