2023-12-10 21:33:30 -08:00
|
|
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
|
2023-12-10 22:04:30 -08:00
|
|
|
int main(int argc, char* argv[]) {
|
2023-12-10 21:33:30 -08:00
|
|
|
ios::sync_with_stdio(0);
|
|
|
|
cin.tie(0);
|
|
|
|
|
2023-12-10 22:04:30 -08:00
|
|
|
bool dontwork = argc == 2 && !strcmp(argv[1], "DONTWORK");
|
|
|
|
|
2023-12-10 21:33:30 -08:00
|
|
|
vector<string> lines;
|
|
|
|
string line;
|
|
|
|
while (getline(cin, line) && !line.empty()) {
|
|
|
|
lines.push_back(line);
|
2023-12-10 22:04:30 -08:00
|
|
|
if (dontwork)
|
|
|
|
goto next1;
|
2023-12-10 21:33:30 -08:00
|
|
|
for (char c : line) {
|
|
|
|
if (c != '.') {
|
|
|
|
goto next1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lines.push_back(line);
|
|
|
|
next1:;
|
|
|
|
}
|
|
|
|
|
2023-12-10 22:04:30 -08:00
|
|
|
if (dontwork)
|
|
|
|
goto next3;
|
2023-12-10 21:33:30 -08:00
|
|
|
for (unsigned int col = 0; col < lines[0].size(); col++) {
|
|
|
|
for (auto& r : lines) {
|
|
|
|
if (r[col] != '.') {
|
|
|
|
goto next2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto& l : lines) {
|
|
|
|
l.insert(l.begin() + col, '.');
|
|
|
|
}
|
|
|
|
col++;
|
|
|
|
next2:;
|
|
|
|
}
|
2023-12-10 22:04:30 -08:00
|
|
|
next3:
|
2023-12-10 21:33:30 -08:00
|
|
|
|
|
|
|
vector<pair<int, int>> gs;
|
|
|
|
for (unsigned int row = 0; row < lines.size(); row++) {
|
|
|
|
for (unsigned int col = 0; col < lines[row].size(); col++) {
|
|
|
|
if (lines[row][col] == '#') {
|
|
|
|
gs.push_back(make_pair(row, col));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
for (unsigned int i = 0; i < gs.size() - 1; i++) {
|
|
|
|
auto& gi = gs[i];
|
|
|
|
for (unsigned int j = i + 1; j < gs.size(); j++) {
|
|
|
|
auto& gj = gs[j];
|
|
|
|
ret += abs(gi.first - gj.first) + abs(gi.second - gj.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << ret << '\n';
|
|
|
|
}
|