-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.cpp
50 lines (45 loc) · 1006 Bytes
/
A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll n,m,k,s=0,temp=0;
char arr[503][503];
bool vis[503][503];
void dfs(ll i, ll j){
vis[i][j] = true;
temp++;
if(temp>(s-k))
arr[i][j] = 'X';
if(!vis[i-1][j] && arr[i-1][j]=='.')
dfs(i-1,j);
if(!vis[i+1][j] && arr[i+1][j]=='.')
dfs(i+1,j);
if(!vis[i][j-1] && arr[i][j-1]=='.')
dfs(i,j-1);
if(!vis[i][j+1] && arr[i][j+1]=='.')
dfs(i,j+1);
}
int main(){
fast;
memset(vis, false, sizeof(vis));
ll x,y;
cin>>n>>m>>k;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
cin>>arr[i][j];
if(arr[i][j]=='.'){
s++;
x = i;
y = j;
}
}
}
dfs(x,y);
for(ll i=1; i<=n;i++){
for(ll j=1;j<=m;j++){
cout<<arr[i][j];
}
cout<<"\n";
}
return 0;
}