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. vector <vector <int>> v;
  16.  
  17. pair <int, int> f(int i, int j, int x1, int y1) {
  18. while(a[i + x1][j + y1] != 'x' and i + x1 <= h and i + x1 > 0 and j + y1 <= w and j + y1 > 0) {
  19. i += x1, j += y1;
  20. if(a[i][j] == 'C') {
  21. if(x1 == -1 and y1 == 0) x1 = 0, y1 = 1;
  22. else if(x1 == 0 and y1 == 1) x1 = 1, y1 = 0;
  23. else if(x1 == 1 and y1 == 0) x1 = 0, y1 = -1;
  24. else if(x1 == 0 and y1 == -1) x1 = -1, y1 = 0;
  25. }
  26. if(a[i][j] == 'A') {
  27. if(x1 == -1 and y1 == 0) x1 = 0, y1 = -1;
  28. else if(x1 == 0 and y1 == 1) x1 = -1, y1 = 0;
  29. else if(x1 == 1 and y1 == 0) x1 = 0, y1 = 1;
  30. else if(x1 == 0 and y1 == -1) x1 = 1, y1 = 0;
  31. }
  32. }
  33. return {i, j};
  34. }
  35.  
  36. int main() {
  37. ios_base::sync_with_stdio(false); cin.tie(nullptr);
  38.  
  39. cin >> n >> w >> h;
  40.  
  41. int nd = 0;
  42. for(int i = 1; i <= h; i++) {
  43. for(int j = 1; j <= w; j++) {
  44. cin >> a[i][j];
  45. mp[i][j] = ++nd;
  46. }
  47. }
  48.  
  49. v.resize(nd+1);
  50. for(int i = 1; i <= h; i++) {
  51. for(int j = 1; j <= w; j++) {
  52. pair <int, int> ind = f(i, j, -1, 0);
  53. if(ind != pair <int, int> {i, j}) v[mp[i][j]].push_back(mp[ind.ff][ind.ss]);
  54. ind = f(i, j, 0, 1);
  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, 0);
  57. if(ind != pair <int, int> {i, j}) v[mp[i][j]].push_back(mp[ind.ff][ind.ss]);
  58. ind = f(i, j, 0, -1);
  59. if(ind != pair <int, int> {i, j}) v[mp[i][j]].push_back(mp[ind.ff][ind.ss]);
  60. }
  61. }
  62.  
  63. for(int i = 1; i <= h; i++) {
  64. for(int j = 1; j <= w; j++) {
  65. cout << i << ' ' << j << "\n";
  66. for(auto k : v[mp[i][j]]) {
  67. cout << k << ' ';
  68. }
  69. cout << '\n';
  70. }
  71. }
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty