2023 day 14
This commit is contained in:
parent
f52cd41da1
commit
f464bbfb26
31
2023/14/main-1.cpp
Normal file
31
2023/14/main-1.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#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);
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
for (unsigned int r = 0; r < lines.size(); r++) {
|
||||
for (unsigned int c = 0; c < lines[r].size(); c++) {
|
||||
if (lines[r][c] == 'O') {
|
||||
lines[r][c] = '.';
|
||||
int rr = r;
|
||||
while (rr != 0 && lines[rr - 1][c] == '.') {
|
||||
rr--;
|
||||
}
|
||||
lines[rr][c] = 'O';
|
||||
ret += lines.size() - rr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << ret << '\n';
|
||||
}
|
101
2023/14/main-2.cpp
Normal file
101
2023/14/main-2.cpp
Normal file
|
@ -0,0 +1,101 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
vector<string> lines;
|
||||
|
||||
const int numtimes = 1000000000;
|
||||
|
||||
inline vector<vector<unsigned int>> hashlines() {
|
||||
vector<vector<unsigned int>> ret;
|
||||
for (auto& row : lines) {
|
||||
vector<unsigned int> retl;
|
||||
for (unsigned int c = 0; c < row.size(); c++) {
|
||||
if (row[c] == 'O') {
|
||||
retl.push_back(c);
|
||||
}
|
||||
}
|
||||
ret.push_back(retl);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
string line;
|
||||
while (getline(cin, line) && !line.empty()) {
|
||||
lines.push_back(line);
|
||||
}
|
||||
|
||||
vector<vector<vector<unsigned int>>> all;
|
||||
|
||||
for (unsigned int i = 0; i < numtimes; i++) {
|
||||
for (unsigned int r = 0; r < lines.size(); r++) {
|
||||
for (unsigned int c = 0; c < lines[r].size(); c++) {
|
||||
if (lines[r][c] == 'O') {
|
||||
lines[r][c] = '.';
|
||||
unsigned int rr = r;
|
||||
while (rr != 0 && lines[rr - 1][c] == '.') {
|
||||
rr--;
|
||||
}
|
||||
lines[rr][c] = 'O';
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto& row : lines) {
|
||||
for (unsigned int c = 0; c < row.size(); c++) {
|
||||
if (row[c] == 'O') {
|
||||
row[c] = '.';
|
||||
unsigned int cc = c;
|
||||
while (cc != 0 && row[cc - 1] == '.') {
|
||||
cc--;
|
||||
}
|
||||
row[cc] = 'O';
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unsigned int r = lines.size() - 1; (int)r >= 0; r--) {
|
||||
for (unsigned int c = 0; c < lines[r].size(); c++) {
|
||||
if (lines[r][c] == 'O') {
|
||||
lines[r][c] = '.';
|
||||
unsigned int rr = r;
|
||||
while (rr != lines.size() - 1 && lines[rr + 1][c] == '.') {
|
||||
rr++;
|
||||
}
|
||||
lines[rr][c] = 'O';
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto& row : lines) {
|
||||
for (unsigned int c = row.size() - 1; (int)c >= 0; c--) {
|
||||
if (row[c] == 'O') {
|
||||
row[c] = '.';
|
||||
unsigned int cc = c;
|
||||
while (cc != row.size() - 1 && row[cc + 1] == '.') {
|
||||
cc++;
|
||||
}
|
||||
row[cc] = 'O';
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto& hashed = hashlines();
|
||||
for (unsigned int j = 0; j < i; j++) {
|
||||
if (all[j] == hashed) {
|
||||
unsigned int diff = i - j;
|
||||
all.push_back(all[(numtimes - j - 1) % diff + j]);
|
||||
goto mainexit;
|
||||
}
|
||||
}
|
||||
all.push_back(hashed);
|
||||
}
|
||||
mainexit:
|
||||
|
||||
auto& lastver = all.back();
|
||||
int ret = 0;
|
||||
for (unsigned int r = 0; r < lastver.size(); r++) {
|
||||
ret += (lastver.size() - r) * lastver[r].size();
|
||||
}
|
||||
|
||||
cout << ret << '\n';
|
||||
}
|
Loading…
Reference in a new issue