2023 day 11
This commit is contained in:
parent
2028e3c1de
commit
813bf64be5
53
2023/11/main-1.cpp
Normal file
53
2023/11/main-1.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
vector<string> lines;
|
||||
string line;
|
||||
while (getline(cin, line) && !line.empty()) {
|
||||
lines.push_back(line);
|
||||
for (char c : line) {
|
||||
if (c != '.') {
|
||||
goto next1;
|
||||
}
|
||||
}
|
||||
lines.push_back(line);
|
||||
next1:;
|
||||
}
|
||||
|
||||
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:;
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
65
2023/11/main-2.cpp
Normal file
65
2023/11/main-2.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
vector<string> lines;
|
||||
string line;
|
||||
while (getline(cin, line) && !line.empty()) {
|
||||
lines.push_back(line);
|
||||
}
|
||||
|
||||
vector<int> erows, ecols;
|
||||
|
||||
for (unsigned int row = 0; row < lines.size(); row++) {
|
||||
for (char c : lines[row]) {
|
||||
if (c != '.') {
|
||||
goto next1;
|
||||
}
|
||||
}
|
||||
erows.push_back(row);
|
||||
next1:;
|
||||
}
|
||||
|
||||
for (unsigned int col = 0; col < lines[0].size(); col++) {
|
||||
for (auto& r : lines) {
|
||||
if (r[col] != '.') {
|
||||
goto next2;
|
||||
}
|
||||
}
|
||||
ecols.push_back(col);
|
||||
next2:;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long 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);
|
||||
for (int erow : erows) {
|
||||
if ((erow - gi.first) * (erow - gj.first) < 0) {
|
||||
ret += 999'999;
|
||||
}
|
||||
}
|
||||
for (int ecol : ecols) {
|
||||
if ((ecol - gi.second) * (ecol - gj.second) < 0) {
|
||||
ret += 999'999;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << ret << '\n';
|
||||
}
|
Loading…
Reference in a new issue