fork download
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. #define ff first
  6. #define ss second
  7. #define ll long long
  8.  
  9. const int N = 505;
  10.  
  11. char a[N][N];
  12.  
  13. int mp[N][N], n, w, h;
  14.  
  15. pair <int, int> dp[N][N][4];
  16.  
  17. vector <vector <int>> v;
  18.  
  19. pair <int, int> f(int i, int j, int x) {
  20. if(dp[i][j][x] != pair <int, int> {0, 0}) return dp[i][j][x];
  21. int x1 = (x % 2 ? 0 : (!x ? -1 : 1)), y1 = (!(x % 2) ? 0 : (x == 1 ? 1 : -1));
  22. if(a[i + x1][j + y1] != 'x' and i + x1 <= h and i + x1 > 0 and j + y1 <= w and j + y1 > 0) {
  23. int xx = x;
  24. i += x1, j += y1;
  25. if(a[i][j] == 'C') {
  26. x++;
  27. if(x == 4) x = 0;
  28. }
  29. if(a[i][j] == 'A') {
  30. x--;
  31. if(x == -1) x = 3;
  32. }
  33. return dp[i][j][xx] = f(i, j, x);
  34. }
  35. return dp[i][j][x] = pair <int, int> {i, j};
  36. }
  37.  
  38. int main() {
  39. ios_base::sync_with_stdio(false); cin.tie(nullptr);
  40.  
  41. cin >> n >> w >> h;
  42.  
  43. int nd = 0;
  44. for(int i = 1; i <= h; i++) {
  45. for(int j = 1; j <= w; j++) {
  46. cin >> a[i][j];
  47. mp[i][j] = ++nd;
  48. }
  49. }
  50.  
  51. v.resize(nd+1);
  52. for(int i = 1; i <= h; i++) {
  53. for(int j = 1; j <= w; j++) {
  54. pair <int, int> ind = f(i, j, 0);
  55. if(ind != pair <int, int> {i, j}) v[mp[i][j]].push_back(mp[ind.ff][ind.ss]);
  56. ind = f(i, j, 1);
  57. if(ind != pair <int, int> {i, j}) v[mp[i][j]].push_back(mp[ind.ff][ind.ss]);
  58. ind = f(i, j, 2);
  59. if(ind != pair <int, int> {i, j}) v[mp[i][j]].push_back(mp[ind.ff][ind.ss]);
  60. ind = f(i, j, 3);
  61. if(ind != pair <int, int> {i, j}) v[mp[i][j]].push_back(mp[ind.ff][ind.ss]);
  62. }
  63. }
  64.  
  65. for(int i = 1; i <= h; i++) {
  66. for(int j = 1; j <= w; j++) {
  67. cout << i << ' ' << j << "\n";
  68. for(auto k : v[mp[i][j]]) {
  69. cout << k << ' ';
  70. }
  71. cout << '\n';
  72. }
  73. }
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty