1
0
Fork 0

Day 9 submission

This commit is contained in:
Marcus Penate 2021-12-09 01:11:44 -05:00
parent 533aae2f1c
commit dfcc3b4f76
15 changed files with 850 additions and 723 deletions

View File

@ -0,0 +1,45 @@
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int height_map[100*100];
for(int i = 0; i < 100; i++)
{
string in;
cin >> in;
for(int j = 0; j < 100; j++)
{
height_map[j+i*100] = (int)in[j]-(int)'0';
}
}
int result = 0;
for(int i = 0; i < 100*100; i++)
{
if (i-100 >= 0 && height_map[i-100] <= height_map[i])
{
continue;
}
if (i+100 < 100*100 && height_map[i+100] <= height_map[i])
{
continue;
}
if (i-1 >= 0 && height_map[i-1] <= height_map[i])
{
continue;
}
if (i+1 < 100*100 && height_map[i+1] <= height_map[i])
{
continue;
}
result += height_map[i]+1;
}
cout << result << endl;
return 0;
}

View File

@ -0,0 +1,82 @@
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <set>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
int height_map[100*100];
for(int i = 0; i < 100; i++)
{
string in;
cin >> in;
for(int j = 0; j < 100; j++)
{
height_map[j+i*100] = (int)in[j]-(int)'0';
}
}
vector<int> basins(3, 0);
for(int i = 0; i < 100*100; i++)
{
if (i-100 >= 0 && height_map[i-100] <= height_map[i])
{
continue;
}
if (i+100 < 100*100 && height_map[i+100] <= height_map[i])
{
continue;
}
if (i-1 >= 0 && height_map[i-1] <= height_map[i])
{
continue;
}
if (i+1 < 100*100 && height_map[i+1] <= height_map[i])
{
continue;
}
queue<pair<int,int>> to_explore;
to_explore.push(pair<int,int>(i-100,i));
to_explore.push(pair<int,int>(i+100,i));
to_explore.push(pair<int,int>(i-1,i));
to_explore.push(pair<int,int>(i+1,i));
set<int> basin;
basin.insert(i);
while(!to_explore.empty())
{
pair<int,int> cur = to_explore.front();
to_explore.pop();
if (cur.first < 0 || cur.first >= 100*100)
{
continue;
}
if (height_map[cur.first] != 9 && height_map[cur.first] > height_map[cur.second])
{
pair<set<int>::iterator,bool> res = basin.insert(cur.first);
if (res.second)
{
to_explore.push(pair<int,int>(cur.first-100,cur.first));
to_explore.push(pair<int,int>(cur.first+100,cur.first));
to_explore.push(pair<int,int>(cur.first-1,cur.first));
to_explore.push(pair<int,int>(cur.first+1,cur.first));
}
}
}
basins.push_back(basin.size());
sort(basins.begin(), basins.end());
basins.erase(basins.begin());
}
cout << basins[0]*basins[1]*basins[2] << endl;
return 0;
}