fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll;
  5. typedef long double ld;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vl;
  8. typedef pair<int, int>pi;
  9. typedef pair<ll, ll>pl;
  10. typedef vector<pi>vpi;
  11. typedef vector<pl>vpl;
  12. typedef vector<vi> vvi;
  13. typedef vector<vl> vvl;
  14. typedef vector<string> vs;
  15. typedef vector<bool> vb;
  16. const long double PI = acos(-1);
  17. const ll oo = LLONG_MAX;
  18. const int MOD = 1e9 + 7;
  19. const int N = 5e2 + 7;
  20. #define all(v) (v).begin(),(v).end()
  21. #define rall(v) (v).rbegin(),(v).rend()
  22. #define read(v) for (auto& it : v) scanf("%d", &it);
  23. #define readl(v) for (auto& it : v) scanf("%lld", &it);
  24. #define print(v) for (auto it : v) printf("%d ", it); puts("");
  25. #define printl(v) for (auto it : v) printf("%lld ", it); puts("");
  26. int n, m, k;
  27. vector<string>v(N);
  28. vector<vector<bool>>vis(N, vector<bool>(N));
  29. int dr[] = { 0,0,-1,1 }, dc[] = { -1,1,0,0 };
  30. void DFS(int r, int c) {
  31. vis[r][c] = true;
  32. for (int i = 0; i < 4; i++) {
  33. int nr = r + dr[i], nc = c + dc[i];
  34. if (nr < 0 || nr >= n || nc < 0 || nc >= m || v[nr][nc] == '#' || v[nr][nc] == 'X' || vis[nr][nc])
  35. continue;
  36. DFS(nr, nc);
  37. }
  38. if (k)
  39. v[r][c] = 'X', k--;
  40. }
  41. void init() {
  42. for (int i = 0; i <= n; i++) {
  43. v[i].clear();
  44. for (int j = 0; j <= m; j++)
  45. vis[i][j] = false;
  46. }
  47. }
  48. void solve() {
  49. scanf("%d %d %d", &n, &m, &k);
  50. init();
  51. for (auto& it : v) {
  52. char c[500];
  53. scanf("%s", &c);
  54. it = c;
  55. }
  56. for (int i = 0; i < n; i++) {
  57. bool oki = false;
  58. for (int j = 0; j < m; j++) {
  59. if (v[i][j] == '.') {
  60. DFS(i, j);
  61. oki = true;
  62. break;
  63. }
  64. }
  65. if (oki)
  66. break;
  67. }
  68. for (int i = 0; i < n; i++)
  69. puts(v[i].c_str());
  70. }
  71. int t = 1;
  72. int main() {
  73. #ifndef ONLINE_JUDGE
  74. freopen("input.txt", "r", stdin);
  75. #endif
  76. //scanf("%d", &t);
  77. while (t--) solve();
  78. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty