2025. 4. 15

 
#include <string>
#include <vector>
#include <cmath>
using namespace std;

string solution(vector<int> numbers, string hand) {
    string answer = "";
    vector<pair<int, int>>call;
    call.push_back({3,1});
    pair<int, int>l = {3,0}, r = {3,2};
    
    for(int i =0; i<3; ++i){
        for(int j =0; j<3; ++j){
            call.push_back({i,j});
        }
    }
    
    for(auto x : numbers){
        if(x%3==1){answer += "L"; l=call[x]; continue;}
        if(x%3==0 && x!=0){answer += "R"; r=call[x]; continue;}
        int cntR = abs(r.first-call[x].first)+abs(r.second-call[x].second);
        int cntL = abs(l.first-call[x].first)+abs(l.second-call[x].second);
        if(cntR != cntL) {
            answer += cntR < cntL? "R" : "L";
            cntR < cntL? r=call[x]:l=call[x];
        }
        else {
            answer += hand == "right"? "R" : "L";
            hand == "right"? r=call[x]:l=call[x];
        }
    }
    
    return answer;
}

한시간 조금 덜 걸렸다!

0번 자리 행열 반대로 적어서 조금 더 오래걸림...

pair<int, int> 해서

int cntR = abs(r.first-call[x].first)+abs(r.second-call[x].second);

이거 구현하는 함수 만들려고 했는데

이게 생각보다 잘 안됐다.

이거는 공부를 조금 더 해야지

+ Recent posts