fork download
  1. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
  2. #pragma GCC optimize("no-stack-protector,fast-math")
  3. #define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  4. #include<iostream>
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define ld long double
  9. #define mk make_pair
  10. #define ull unsigned long long int
  11. #define pi pair<int , int>
  12. #define oo 1e9+50
  13. #define endl "\n"
  14. #define OO (ll)4e18+5
  15. #define eps 1e-15
  16. //int dx[8]={1, 1, 1,-1, -1,-1,0,0};
  17. //int dy[8]={0, -1,1, 0, 1,-1, 1,-1};
  18. //int dx[8]={-1,-2,-2,-1,1,2, 2,1};
  19. //int dy[8]={-2,-1, 1, 2,2,1,-1,-2};
  20. int dx []={1,0,0,-1};
  21. int dy []={0,1,-1,0};
  22. double PI=acos(-1);
  23. const int N = 5e2+5 , M = 1e2+2/2 , MOD =1e9+7 , inf=0x3f3f3f3f;
  24. int n,m,k;
  25. char x[N][N];
  26. bool vis[N][N];
  27. bool valid(int a,int b){
  28. return (a>=0&&a<n&&b>=0&&b<m&&x[a][b]=='.');
  29. }
  30. void bfs(int i, int j,int x, int y){
  31. vis[i][j]=1;
  32. queue<pi>q;
  33. q.push(mk(i,j));
  34. while(!q.empty())
  35. {
  36. auto top=q.front();
  37. q.pop();
  38. for(int d=0;d<4;d++)
  39. {
  40. int ni=top.first+dx[i];
  41. int nj=top.second+dy[i];
  42. if(valid(ni,nj))
  43. {
  44. q.push(mk(ni,nj));
  45. vis[ni][nj]=1;
  46. }
  47. if(vis[x][y])return;
  48. }
  49. }
  50. }
  51. //void show(){
  52. // for(int i=1;i<=n;i++)
  53. // {
  54. // printf("Node %d\n",i);
  55. // for(auto a:adj[i])printf("%d ",a);
  56. // printf("\n");
  57. // }
  58. //}
  59. void show(){
  60. for(int i=0;i<n;i++)
  61. {
  62. for(int j=0;j<m;j++)
  63. printf("%c",x[i][j]);
  64. printf("\n");
  65. }
  66. }
  67. int main(){
  68. IO;
  69. #ifndef ONLINE_JUDGE
  70. freopen("input.in", "r", stdin);
  71. //freopen("output.in","w",stdout);
  72. //clock_t tStart = clock();
  73. //cerr<<fixed<<setprecision(10)<<"Time Taken: "<<(double)(clock()- tStart)/CLOCKS_PER_SEC<<endl;
  74. #endif
  75. scanf("%d %d %d",&n,&m,&k);
  76. for(int i=0;i<n;i++)
  77. for(int j=0;j<m;j++)
  78. scanf(" %c",&x[i][j]);
  79.  
  80. bfs(0,1,4,2);
  81. for(int i=0;i<n;i++)
  82. {
  83. for(int j=0;j<m;j++)
  84. {
  85. if(k>0)
  86. {
  87. if(!vis[i][j]&&x[i][j]=='.')k--,cout<<'X';
  88. else cout<<x[i][j];
  89. }
  90. else cout<<x[i][j];
  91. }
  92. cout<<endl;
  93. }
  94. return 0;
  95. }
  96.  
Success #stdin #stdout 0s 5500KB
stdin
Standard input is empty
stdout
Standard output is empty