fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define sr(a) sort(a.begin(), a.end())
  5. #define rv(a) reverse(a.begin(), a.end())
  6. #define all(a) a.begin(), a.end()
  7.  
  8.  
  9.  
  10.  
  11. #ifndef ONLINE_JUDGE
  12. #include "debug.cpp"
  13. #else
  14. #define debug(...)
  15. #define debugArr(...)
  16. #endif
  17. int n,m,k;
  18. vector<vector<char>> a;
  19. vector<vector<bool>> vis;
  20. int dx[] = {0,1,0,-1};
  21. int dy[] = {-1,0,1,0};
  22.  
  23. void dfs(int i,int j)
  24. {
  25. if(vis[i][j]) return;
  26. vis[i][j] = true;
  27. for(int t = 0; t<4; t++)
  28. {
  29. int new_x = i + dx[t];
  30. int new_y = j + dy[t];
  31. if(new_x >= 0 && new_x < n && new_y >= 0 && new_y < m)
  32. {
  33. if(a[new_x][new_y] == '.')
  34. {
  35. dfs(new_x,new_y);
  36. }
  37. }
  38. }
  39. if(k>0)
  40. {
  41. k--;
  42. a[i][j] = 'X';
  43. }
  44. }
  45. int main()
  46. {
  47. ios_base::sync_with_stdio(false);
  48. cin.tie(NULL);
  49. // freopen("input.in", "r", stdin);
  50. // freopen("output.out", "w", stdout);
  51.  
  52. cin>>n>>m>>k;
  53. a.resize(n+1,vector<char>(m+1));
  54. vis.resize(n+1,vector<bool>(m+1,false));
  55. for(int i = 0 ; i <n; i++)
  56. {
  57. for(int j = 0; j<m; j++)
  58. {
  59. cin>>a[i][j];
  60. }
  61. }
  62. for(int i = 0 ; i <n; i++)
  63. {
  64. for(int j = 0; j<m; j++)
  65. {
  66. if(!vis[i][j] && a[i][j] == '.')
  67. {
  68. dfs(i,j);
  69. }
  70. }
  71. }
  72.  
  73. for(int i = 0 ; i <n; i++)
  74. {
  75. for(int j = 0; j<m; j++)
  76. {
  77. cout << a[i][j];
  78. }
  79. cout <<"\n";
  80. }
  81. return 0;
  82. }
  83.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty