#include <iostream>
#define int long long int
int abss(int x)
{
if (x < 0)
return -x;
else
return x;
}
int calc(std::pair<int, int> from, std::pair<int, int> to, int m)
{
++m;
int length = abss(from.first - to.first);
int overfirst = ((length / m) + 1) * m;
int underfirst = (length / m) * m;
int val = length / m;
int oneover = abss(overfirst - length);
int oneunder = abss(underfirst - length);
// std::cout << firstDiff << " ";
int length2 = abss(from.second - to.second);
int overfirst2 = ((length2 / m) + 1) * m;
int underfirst2 = (length2 / m) * m;
int val2 = length2 / m;
int oneover2 = abss(overfirst2 - length2);
int oneunder2 = abss(underfirst2 - length2);
int min = 1e15;
//OVER OVER
min = std::min(min, abss(overfirst - length) + abss(overfirst2 - length2) + ((length / m) + 1LL) * 2LL + ((length2 / m) + 1LL) * 2LL);
std::cout << min << " ";
//UNDER OVER
if (val > 0 || length == 0)
{
min = std::min(min, oneunder + oneover2 + val + ((length2 / m) + 1LL) * 2LL);
}
else
{
min = std::min(min, oneunder + oneover2 + val + ((length2 / m) + 1LL) * 2LL + 2LL);
}
std::cout << min << " ";
//OVER UNDER
if (val2 > 0 || length2 == 0)
{
min = std::min(min, oneover + oneunder2 + ((length / m) + 1LL) * 2LL + val2);
}
else
{
min = std::min(min, oneover + oneunder2 + ((length / m) + 1LL) * 2LL + val2 + 2LL);
}
std::cout << min << " ";
//UNDER UNDER
int add = 4LL;
if (val > 0 || length == 0)
add -= 2;
if (val2 > 0 || length2 == 0)
add -= 2;
min = std::min(min, oneunder + oneunder2 + val + val2 + add);
std::cout << min << " ";
return min;
}
main()
{
int k, m;
std::cin >> k >> m;
std::pair<int, int> hole[510][110];
int mini[510][110];
int holeNumber[510];
std::pair<int, int> start, ende;
std::cin >> start.first >> start.second >> ende.first >> ende.second;
holeNumber[0] = 1;
holeNumber[k] = 1;
hole[0][0].first = start.first;
hole[0][0].second = start.second;
hole[k][0].first = ende.first;
hole[k][0].second = ende.second;
mini[0][0] = 0;
mini[k][0] = 1e15;
for (int i = 1; i <= k - 1; ++i)
{
std::cin >> holeNumber[i];
for (int j = 0; j < holeNumber[i]; ++j)
{
mini[i][j] = 1e15;
std::cin >> hole[i][j].first >> hole[i][j].second;
}
}
if (m == 1)
{
for (int i = 1; i <= k; ++i)
{
for (int j = 0; j < holeNumber[i]; ++j)
{
for (int q = 0; q < holeNumber[i - 1]; ++q)
{
int val = abss(hole[i][j].first - hole[i - 1][q].first) + abss(hole[i][j].second - hole[i - 1][q].second);
mini[i][j] = std::min(mini[i][j], val + mini[i - 1][q]);
}
}
}
std::cout << mini[k][0];
return 0;
}
for (int i = 1; i <= k; ++i)
{
for (int j = 0; j < holeNumber[i]; ++j)
{
for (int q = 0; q < holeNumber[i - 1]; ++q)
{
int val = calc(hole[i][j], hole[i - 1][q], m);
// std::cout << val << " " << j << " " << q << "\n";
mini[i][j] = std::min(mini[i][j], val + mini[i - 1][q]);
}
}
}
std::cout << mini[k][0];
}
Compilation message
obelisk.cpp:74:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1256 KB |
Output is correct |
3 |
Correct |
3 ms |
1332 KB |
Output is correct |
4 |
Correct |
3 ms |
1332 KB |
Output is correct |
5 |
Correct |
3 ms |
1384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
1532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
501 ms |
15612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
655 ms |
33116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |