|
|
|
@ -15,20 +15,85 @@ enum Direction{ |
|
|
|
|
struct Blizzard{ |
|
|
|
|
vi2d pos; |
|
|
|
|
Direction dir; |
|
|
|
|
bool moved=false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
int maxWidth=0; |
|
|
|
|
vi2d playerPos={1,0}; |
|
|
|
|
std::vector<std::vector<std::vector<Blizzard>>>boardState; |
|
|
|
|
|
|
|
|
|
std::vector<std::vector<Blizzard>> getBoard(int minute){ |
|
|
|
|
if (minute<boardState.size()){ |
|
|
|
|
return boardState[minute]; |
|
|
|
|
} else { |
|
|
|
|
std::vector<std::vector<Blizzard>> prevBoardState=getBoard(minute-1); |
|
|
|
|
for (int y=0;y<prevBoardState.size();y++){ |
|
|
|
|
std::vector<Blizzard>&blizzardList=prevBoardState[y]; |
|
|
|
|
for (int x=0;x<blizzardList.size();x++){ |
|
|
|
|
Blizzard&b=blizzardList[x]; |
|
|
|
|
b.moved=false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (int y=0;y<prevBoardState.size();y++){ |
|
|
|
|
std::vector<Blizzard>&blizzardList=prevBoardState[y]; |
|
|
|
|
blizzardList.reserve(100); |
|
|
|
|
for (int x=0;x<blizzardList.size();x++){ |
|
|
|
|
Blizzard&b=blizzardList[x]; |
|
|
|
|
if (!b.moved){ |
|
|
|
|
b.moved=true; |
|
|
|
|
switch (b.dir){ |
|
|
|
|
case NORTH:{ |
|
|
|
|
vi2d dest={b.pos.x,b.pos.y-1}; |
|
|
|
|
if (dest.y<1){ |
|
|
|
|
dest.y=prevBoardState.size()-2; |
|
|
|
|
} |
|
|
|
|
b.pos=dest; |
|
|
|
|
(&prevBoardState[dest.y])->push_back(b); |
|
|
|
|
blizzardList.erase(blizzardList.begin()+x--); |
|
|
|
|
}break; |
|
|
|
|
case EAST:{ |
|
|
|
|
vi2d dest={b.pos.x+1,b.pos.y}; |
|
|
|
|
if (dest.x>=maxWidth-1){ |
|
|
|
|
dest.x=1; |
|
|
|
|
} |
|
|
|
|
b.pos=dest; |
|
|
|
|
}break; |
|
|
|
|
case SOUTH:{ |
|
|
|
|
vi2d dest={b.pos.x,b.pos.y+1}; |
|
|
|
|
if (dest.y>=prevBoardState.size()-1){ |
|
|
|
|
dest.y=1; |
|
|
|
|
} |
|
|
|
|
b.pos=dest; |
|
|
|
|
(&prevBoardState[dest.y])->push_back(b); |
|
|
|
|
blizzardList.erase(blizzardList.begin()+x--); |
|
|
|
|
}break; |
|
|
|
|
case WEST:{ |
|
|
|
|
vi2d dest={b.pos.x-1,b.pos.y}; |
|
|
|
|
if (dest.x<1){ |
|
|
|
|
dest.x=maxWidth-2; |
|
|
|
|
} |
|
|
|
|
b.pos=dest; |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
boardState.push_back(prevBoardState); |
|
|
|
|
return prevBoardState; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
|
{ |
|
|
|
|
std::ifstream file("input"); |
|
|
|
|
std::vector<std::vector<std::vector<Blizzard>>>boardState; |
|
|
|
|
std::ifstream file("smallinput"); |
|
|
|
|
std::vector<std::vector<Blizzard>>board; |
|
|
|
|
while (file.good()){ |
|
|
|
|
std::string line; |
|
|
|
|
std::vector<std::vector<Blizzard>>board; |
|
|
|
|
std::getline(file,line); |
|
|
|
|
if (line.length()>0){ |
|
|
|
|
std::cout<<line<<std::endl; |
|
|
|
|
std::vector<Blizzard>boardRow; |
|
|
|
|
boardRow.reserve(100); |
|
|
|
|
for (int i=0;i<line.length();i++){ |
|
|
|
|
if (line[i]!='#'&&line[i]!='.'){ |
|
|
|
|
boardRow.push_back({{i,(int)board.size()},line[i]=='^'?Direction::NORTH:line[i]=='>'?Direction::EAST:line[i]=='v'?Direction::SOUTH:line[i]=='<'?Direction::WEST:Direction::INVALID}); |
|
|
|
@ -37,9 +102,9 @@ int main() |
|
|
|
|
maxWidth=line.length(); |
|
|
|
|
board.push_back(boardRow); |
|
|
|
|
} |
|
|
|
|
boardState.push_back(board); |
|
|
|
|
} |
|
|
|
|
for (int d=0;d<boardState.size();d++){ |
|
|
|
|
boardState.push_back(board); |
|
|
|
|
/*for (int d=0;d<boardState.size();d++){
|
|
|
|
|
for (int y=0;y<boardState[d].size();y++){ |
|
|
|
|
int prevBlizzard=-1; |
|
|
|
|
for (int x=0;x<boardState[d][y].size();x++){ |
|
|
|
@ -71,7 +136,48 @@ int main() |
|
|
|
|
} |
|
|
|
|
std::cout<<std::endl; |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
for (int i=0;i<10;i++){ |
|
|
|
|
std::cout<<"Board "<<i+1<<std::endl; |
|
|
|
|
std::vector<std::vector<Blizzard>>board=getBoard(i+1); |
|
|
|
|
for (int y=0;y<board.size();y++){ |
|
|
|
|
int prevBlizzard=-1; |
|
|
|
|
std::vector<Blizzard>sorted=board[y]; |
|
|
|
|
std::sort(sorted.begin(),sorted.end(),[](Blizzard&b1,Blizzard&b2){return b1.pos.x<b2.pos.y;}); |
|
|
|
|
for (int x=0;x<sorted.size();x++){ |
|
|
|
|
Blizzard&b=sorted[x]; |
|
|
|
|
for (int k=prevBlizzard;k<b.pos.x-1;k++){ |
|
|
|
|
std::cout<<'.'; |
|
|
|
|
} |
|
|
|
|
if (prevBlizzard<b.pos.x){ |
|
|
|
|
switch (b.dir){ |
|
|
|
|
case NORTH:{ |
|
|
|
|
std::cout<<'^'; |
|
|
|
|
}break; |
|
|
|
|
case EAST:{ |
|
|
|
|
std::cout<<'>'; |
|
|
|
|
}break; |
|
|
|
|
case SOUTH:{ |
|
|
|
|
std::cout<<'v'; |
|
|
|
|
}break; |
|
|
|
|
case WEST:{ |
|
|
|
|
std::cout<<'<'; |
|
|
|
|
}break; |
|
|
|
|
case INVALID:{ |
|
|
|
|
std::cout<<'?'; |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
prevBlizzard=b.pos.x; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (int k=prevBlizzard;k<maxWidth-1;k++){ |
|
|
|
|
std::cout<<'.'; |
|
|
|
|
} |
|
|
|
|
std::cout<<std::endl; |
|
|
|
|
} |
|
|
|
|
std::cout<<"=================="<<std::endl<<std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|