#include <string>
#include <vector>
#include <map>
#include <iostream>
using namespace std;
 
int solution(vector<int> arrows) 
{
    int roomCnt = 0;
    map<pair<intint>int> vertex_visited;
    map<pair<pair<intint>pair<intint>>int> edge_visited;
 
    int dx[8= {-1-101110-1};
    int dy[8= {01110-1-1-1};
    
    int x = 0;
    int y = 0;
    vertex_visited[{x, y}] = 1;
    for(int i = 0; i < arrows.size(); i++)
    {
        // X자의 교차 형태도 세줘야해서 2배
        for(int j = 0; j < 2; j++)
        {
            int xpos = x + dx[arrows[i]];
            int ypos = y + dy[arrows[i]];
            
            if(vertex_visited[{xpos, ypos}] == 1)
            {
                if(edge_visited[{{x, y}, {xpos, ypos}}] == 0 || edge_visited[{{xpos, ypos}, {x, y}}] == 0)
                {
                    roomCnt++;
                }
            }
 
            // vertex 체크
            vertex_visited[{xpos, ypos}] = 1;
            
            // edge 체크
            edge_visited[{{x, y}, {xpos, ypos}}] = 1;
            edge_visited[{{xpos, ypos}, {x, y}}] = 1;
            
            x = xpos;
            y = ypos;            
        }   
    }
 
    return roomCnt;
}
cs

+ Recent posts