C++ Library for Competitive Programming
/*
* @title その他/回転
*
* verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2953
*/
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include "emthrm/misc/rotate.hpp"
int main() {
int h, w;
std::cin >> h >> w;
std::vector<std::vector<char>> c(h, std::vector<char>(w));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
std::cin >> c[i][j];
}
}
c = emthrm::rotate<45>(c);
h = c.size();
w = c.front().size();
int y_min = h, y_max = -1, x_min = w, x_max = -1;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (c[i][j] == 'B') {
y_min = std::min(y_min, i);
y_max = std::max(y_max, i);
x_min = std::min(x_min, j);
x_max = std::max(x_max, j);
}
}
}
std::cout << std::max(y_max - y_min, x_max - x_min) << '\n';
return 0;
}
#line 1 "test/misc/rotate.test.cpp"
/*
* @title その他/回転
*
* verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2953
*/
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#line 1 "include/emthrm/misc/rotate.hpp"
#include <cassert>
#line 6 "include/emthrm/misc/rotate.hpp"
namespace emthrm {
template <int ANGLE, typename T>
std::vector<std::vector<T>> rotate(const std::vector<std::vector<T>>& grid,
const T space = ' ') {
static_assert(ANGLE == 45 || ANGLE == 90);
const int h = grid.size(), w = grid.front().size();
std::vector<std::vector<T>> rotated_grid;
if constexpr (ANGLE == 45) {
rotated_grid.assign(h + w - 1, std::vector<T>(h + w - 1, space));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
rotated_grid[i + j][i - j + w - 1] = grid[i][j];
}
}
} else {
rotated_grid.assign(w, std::vector<T>(h));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
rotated_grid[w - 1 - j][i] = grid[i][j];
}
}
}
return rotated_grid;
}
} // namespace emthrm
#line 13 "test/misc/rotate.test.cpp"
int main() {
int h, w;
std::cin >> h >> w;
std::vector<std::vector<char>> c(h, std::vector<char>(w));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
std::cin >> c[i][j];
}
}
c = emthrm::rotate<45>(c);
h = c.size();
w = c.front().size();
int y_min = h, y_max = -1, x_min = w, x_max = -1;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (c[i][j] == 'B') {
y_min = std::min(y_min, i);
y_max = std::max(y_max, i);
x_min = std::min(x_min, j);
x_max = std::max(x_max, j);
}
}
}
std::cout << std::max(y_max - y_min, x_max - x_min) << '\n';
return 0;
}