Home BOJ. Roll The Dice (14499)
Post
Cancel

BOJ. Roll The Dice (14499)

[Link] https://www.acmicpc.net/problem/14499


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 987654321;
int n, m, ci, cj, k;
int map[20][20];
int dice[6] = { 0, 0, 0, 0, 0, 0 }; // x y z -x -y -z

void move(int dir) {
  if(dir == 4){
    if(ci == n - 1) return;
    ci++;
    int top = dice[2];
    dice[2] = dice[3], dice[3] = dice[5], dice[5] = dice[0], dice[0] = top;
  } else if(dir == 3){
    if(ci == 0) return;
    ci--;
    int top = dice[2];
    dice[2] = dice[0], dice[0] = dice[5], dice[5] = dice[3], dice[3] = top;
  } else if(dir == 2){
    if(cj == 0) return;
    cj--;
    int top = dice[2];
    dice[2] = dice[1], dice[1] = dice[5], dice[5] = dice[4], dice[4] = top;
  } else {
    if(cj == m - 1) return;
    cj++;
    int top = dice[2];
    dice[2] = dice[4], dice[4] = dice[5], dice[5] =  dice[1],  dice[1] = top;
  }
  if(map[ci][cj]) {
    dice[5] = map[ci][cj];
    map[ci][cj] = 0;
  }
  else map[ci][cj] = dice[5];
  cout << dice[2] << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cin >> n >> m >> ci >> cj >> k;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++) cin >> map[i][j];

  int dir;
  for(int i = 0; i < k; i++) {
    cin >> dir;
    move(dir);
  }

  return 0;
}
This post is licensed under CC BY 4.0 by the author.