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
| signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, x, y; std::cin >> n >> m >> x >> y;
std::vector g(n, std::vector<char>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { std::cin >> g[i][j]; } }
auto move = [&](int op, int z) { if (op == 1) { int p = 0; std::vector<char> tmp(m); for (int i = 1; i < m; i++) { tmp[i] = g[z][p++]; } tmp[0] = g[z][m - 1]; g[z] = tmp; } else { int p = 0; std::vector<int> tmp(n); for (int i = 1; i < n; i++) { tmp[i] = g[p++][z]; } tmp[0] = g[n - 1][z]; for (int i = 0; i < n; i++) { g[i][z] = tmp[i]; } } };
int p, q; std::cin >> p >> q;
std::vector<int> op(q), z(q); for (int i = 0; i < q; i++) { std::cin >> op[i] >> z[i]; z[i] -= 1; } for (int i = 0; i < p; i++) { for (int j = 0; j < q; j++) { move(op[j], z[j]); } }
std::cout << g[x - 1][y - 1] << "\n";
return 0; }
|