generated from sigonasr2/CPlusPlusProjectTemplate
Fix this up?
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
c205e9a110
commit
95ac19515e
Binary file not shown.
79
main.cpp
79
main.cpp
@ -1,15 +1,36 @@
|
|||||||
#define OLC_PGE_APPLICATION
|
#define OLC_PGE_APPLICATION
|
||||||
#include "pixelGameEngine.h"
|
#include "pixelGameEngine.h"
|
||||||
#include "olcutils.h"
|
#include "olcutils.h"
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
using namespace olc;
|
using namespace olc;
|
||||||
|
std::map<std::string,bool>blocks;
|
||||||
|
std::map<std::string,bool>trappedBlocks;
|
||||||
|
int minX=0,maxX=0,minY=0,maxY=0,minZ=0,maxZ=0;
|
||||||
|
|
||||||
|
bool escape(int x,int y,int z,std::map<std::string,bool>visited){
|
||||||
|
visited[std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z)]=true;
|
||||||
|
if (x<=minX||x>=maxX||y<=minY||y>=maxY||z<=minZ||z>=maxZ){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (blocks.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z))!=blocks.end()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (visited.find(std::to_string(x+1)+"_"+std::to_string(y)+"_"+std::to_string(z))==visited.end()&&escape(x+1,y,z,visited)||
|
||||||
|
visited.find(std::to_string(x-1)+"_"+std::to_string(y)+"_"+std::to_string(z))==visited.end()&&escape(x-1,y,z,visited)||
|
||||||
|
visited.find(std::to_string(x)+"_"+std::to_string(y+1)+"_"+std::to_string(z))==visited.end()&&escape(x,y+1,z,visited)||
|
||||||
|
visited.find(std::to_string(x)+"_"+std::to_string(y-1)+"_"+std::to_string(z))==visited.end()&&escape(x,y-1,z,visited)||
|
||||||
|
visited.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z+1))==visited.end()&&escape(x,y,z+1,visited)||
|
||||||
|
visited.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z-1))==visited.end()&&escape(x,y,z-1,visited)){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::map<std::string,bool>blocks;
|
std::ifstream file("input");
|
||||||
std::ifstream file("testinput");
|
|
||||||
int minX=0,maxX=0,minY=0,maxY=0,minZ=0,maxZ=0;
|
|
||||||
int surfaceArea=0;
|
int surfaceArea=0;
|
||||||
while (file.good()){
|
while (file.good()){
|
||||||
std::string line;
|
std::string line;
|
||||||
@ -25,9 +46,9 @@ int main()
|
|||||||
std::cout<<x<<","<<y<<","<<z<<std::endl;
|
std::cout<<x<<","<<y<<","<<z<<std::endl;
|
||||||
minX=std::min(x,minX);
|
minX=std::min(x,minX);
|
||||||
maxX=std::max(x,maxX);
|
maxX=std::max(x,maxX);
|
||||||
minY=std::min(y,maxY);
|
minY=std::min(y,minY);
|
||||||
maxY=std::max(y,maxY);
|
maxY=std::max(y,maxY);
|
||||||
minZ=std::min(z,maxZ);
|
minZ=std::min(z,minZ);
|
||||||
maxZ=std::max(z,maxZ);
|
maxZ=std::max(z,maxZ);
|
||||||
if (blocks.find(std::to_string(x)+"_"+std::to_string(y-1)+"_"+std::to_string(z))==blocks.end()){
|
if (blocks.find(std::to_string(x)+"_"+std::to_string(y-1)+"_"+std::to_string(z))==blocks.end()){
|
||||||
surfaceArea++;
|
surfaceArea++;
|
||||||
@ -59,26 +80,52 @@ int main()
|
|||||||
} else {
|
} else {
|
||||||
surfaceArea--;
|
surfaceArea--;
|
||||||
}
|
}
|
||||||
if (blocks.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z))==blocks.end()){
|
blocks[std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z)]=true;
|
||||||
blocks[std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z)]=true;
|
|
||||||
} else {
|
|
||||||
std::cout<<"DUPLICATE FOUND!"<<std::endl;
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
std::cout<<surfaceArea<<std::endl;
|
std::cout<<surfaceArea<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int sum=0;
|
int trappedSurfaceArea=0;
|
||||||
for (int x=-minX;x<=maxX;x++){
|
for (int x=-minX;x<=maxX;x++){
|
||||||
for (int y=-minY;y<=maxY;y++){
|
for (int y=-minY;y<=maxY;y++){
|
||||||
for (int z=-minZ;z<=maxZ;z++){
|
for (int z=-minZ;z<=maxZ;z++){
|
||||||
if (escape(x,y,z)){
|
if (!escape(x,y,z,{})){
|
||||||
sum++;
|
trappedBlocks[std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z)]=true;
|
||||||
|
std::cout<<"Block "<<std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z)<<" is trapped"<<std::endl;
|
||||||
|
if (trappedBlocks.find(std::to_string(x)+"_"+std::to_string(y-1)+"_"+std::to_string(z))==trappedBlocks.end()){
|
||||||
|
trappedSurfaceArea++;
|
||||||
|
} else {
|
||||||
|
trappedSurfaceArea--;
|
||||||
|
}
|
||||||
|
if (trappedBlocks.find(std::to_string(x)+"_"+std::to_string(y+1)+"_"+std::to_string(z))==trappedBlocks.end()){
|
||||||
|
trappedSurfaceArea++;
|
||||||
|
} else {
|
||||||
|
trappedSurfaceArea--;
|
||||||
|
}
|
||||||
|
if (trappedBlocks.find(std::to_string(x-1)+"_"+std::to_string(y)+"_"+std::to_string(z))==trappedBlocks.end()){
|
||||||
|
trappedSurfaceArea++;
|
||||||
|
} else {
|
||||||
|
trappedSurfaceArea--;
|
||||||
|
}
|
||||||
|
if (trappedBlocks.find(std::to_string(x+1)+"_"+std::to_string(y)+"_"+std::to_string(z))==trappedBlocks.end()){
|
||||||
|
trappedSurfaceArea++;
|
||||||
|
} else {
|
||||||
|
trappedSurfaceArea--;
|
||||||
|
}
|
||||||
|
if (trappedBlocks.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z-1))==trappedBlocks.end()){
|
||||||
|
trappedSurfaceArea++;
|
||||||
|
} else {
|
||||||
|
trappedSurfaceArea--;
|
||||||
|
}
|
||||||
|
if (trappedBlocks.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z+1))==trappedBlocks.end()){
|
||||||
|
trappedSurfaceArea++;
|
||||||
|
} else {
|
||||||
|
trappedSurfaceArea--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout<<surfaceArea-sum<<std::endl;
|
std::cout<<surfaceArea-trappedSurfaceArea<<std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user