diff --git a/036.md b/036.md new file mode 100644 index 0000000..1aae97f --- /dev/null +++ b/036.md @@ -0,0 +1,64 @@ +# 036 - Max Manhattan Distance (★5) + +## 解答 + +```cpp +#include +#include +#include // std::numeric_limits<> +#include // std::min(), std::max() +#include // std::abs() + +struct Point +{ + long long x, y; +}; + +int main() +{ + // N 個の点, Q 個のクエリ + int N, Q; + std::cin >> N >> Q; + + std::vector P(N); + for (auto& p : P) + { + long long X, Y; + std::cin >> X >> Y; + + // 45 度の回転(√2 倍の拡大を伴う) + p.x = (X - Y); + p.y = (X + Y); + } + + // 各軸における最小値と最大値を求める + long long minX = std::numeric_limits::max(); + long long maxX = std::numeric_limits::lowest(); + long long minY = std::numeric_limits::max(); + long long maxY = std::numeric_limits::lowest(); + for (auto& p : P) + { + minX = std::min(minX, p.x); + maxX = std::max(maxX, p.x); + minY = std::min(minY, p.y); + maxY = std::max(maxY, p.y); + } + + // 各クエリについて + for (int i = 0; i < Q; ++i) + { + int T; + std::cin >> T; + --T; + + // チェビシェフ距離の最大値を求める + const Point p = P[T]; + const long long a = std::abs(p.x - minX); + const long long b = std::abs(p.x - maxX); + const long long c = std::abs(p.y - minY); + const long long d = std::abs(p.y - maxY); + + std::cout << std::max({ a, b, c, d }) << '\n'; + } +} +``` diff --git a/README.md b/README.md index 9abb48e..532ed04 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ C++17 標準ライブラリの機能を優先して使い、競技プログラ |021| | | | | |[029](https://atcoder.jp/contests/typical90/tasks/typical90_ac)|[Long Bricks](./029.md)|★5|(1) [👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/029-01.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/029-01.cpp),[📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/029-02.cpp)
(2) [👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/029-02.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/029-03.cpp)|(解法 1) 「座標圧縮」で効率化
(解法 2) 区間に対する処理は「セグメント木」| |030| | | | | -|036| | | | | +|[036](https://atcoder.jp/contests/typical90/tasks/typical90_aj)|[Max Manhattan Distance](./036.md)|★5|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/036.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/036.cpp)|マンハッタン距離は 45 度回転| |[037](https://atcoder.jp/contests/typical90/tasks/typical90_ak)|[Don't Leave the Spice](./037.md)|★5|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/037.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/037.cpp)|DP をセグメント木で高速化| |039| | | | | |051| | | | |