#include <cstdio>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include <map>
#define ll long long
using namespace std;
int dice[7] ={0, 1,2,3,4,5,6};
int dice_num[7] = {0, 0,0,0,0,0,0};
int dr[4] = {0, 0, -1, 1};
int dc[4] = {1, -1, 0, 0};
int board[22][22];
int N,M,r,c,K,d;
void changeDir(int d){
int tmp[7] = {0,};
if(d == 1){
tmp[3] = dice[1];
tmp[2] = dice[2];
tmp[6] = dice[3];
tmp[1] = dice[4];
tmp[5] = dice[5];
tmp[4] = dice[6];
}else if(d == 2){
tmp[4] = dice[1];
tmp[2] = dice[2];
tmp[1] = dice[3];
tmp[6] = dice[4];
tmp[5] = dice[5];
tmp[3] = dice[6];
}else if(d == 3){
tmp[2] = dice[1];
tmp[6] = dice[2];
tmp[3] = dice[3];
tmp[4] = dice[4];
tmp[1] = dice[5];
tmp[5] = dice[6];
}else if(d == 4){
tmp[5] = dice[1];
tmp[1] = dice[2];
tmp[3] = dice[3];
tmp[4] = dice[4];
tmp[6] = dice[5];
tmp[2] = dice[6];
}
for(int i=1;i<=6;i++)
dice[i] = tmp[i];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M >> r >> c >> K;
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
cin >> board[i][j];
while(K--)
{
cin >> d;
int nr = r + dr[d-1];
int nc = c + dc[d-1];
if(nr <0 or nc<0 or nr>=N or nc>=M) continue;
changeDir(d);
if(board[nr][nc] != 0){
dice_num[dice[6]] = board[nr][nc];
board[nr][nc] = 0;
}else{
board[nr][nc] = dice_num[dice[6]];
}
r = nr;
c = nc;
cout << dice_num[dice[1]] << '\n';
}
return 0;
}
- 핵심
주사위를 굴릴 때
마다 up / back / right / left / front / bottom
에 있는 주사위 면을 갱신
해줘한다