https://school.programmers.co.kr/learn/courses/30/lessons/118670


#include <string>

#include <vector>

#include <deque>


using namespace std;


vector<vector<int>> solution(vector<vector<int>> rc, vector<string> operations) {

    deque<int> ll;

    deque<int> rr;

    deque<deque<int>> mm;

    

    for (int i = 0; i < rc.size(); i++) {

        ll.push_back(rc[i][0]);

        rr.push_back(rc[i][rc[i].size() - 1]);

    }

    

    for (int i = 0; i < rc.size(); i++) {

        mm.push_back(deque<int>());

        for (int j = 1; j < rc[i].size() - 1; j++)

            mm[i].push_back(rc[i][j]);

    }

    

    for (auto& r : operations) {

        if (r[0] == 'S') {

            ll.push_front(ll.back());

            ll.pop_back();

            rr.push_front(rr.back());

            rr.pop_back();

            mm.push_front(mm.back());

            mm.pop_back();

        } else {

            mm[0].push_front(ll[0]);

            ll.pop_front();

            rr.push_front(mm[0].back());

            mm[0].pop_back();

            mm.back().push_back(rr.back());

            rr.pop_back();

            ll.push_back(mm.back().front());

            mm.back().pop_front();

        }

    }

    

    for (int i = 0; i < rc.size(); i++) {

        rc[i][0] = ll[i];

        for (int j = 1; j < rc[i].size() - 1; j++) {

            rc[i][j] = mm[i][j-1];

        }

        rc[i][rc[0].size() - 1] = rr[i];

    }

                          

    return rc;

}



로직은 맞는거 같음