Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bismillahir Rahman-ir Rahim
- #include <bits/stdc++.h>
- using namespace std;
- #define debug(x) cout << '>' << #x << " : " << x << endl;
- #define all(c) c.begin(), c.end()
- #define F first
- #define S second
- typedef unsigned long long ull;
- typedef long long ll;
- int dx[] = {1, -1, 0, 0};
- int dy[] = {0, 0, 1, -1};
- char mat[5000][5000];
- bool valid(int x, int y, int n, int m){
- if(x >= 0 and x <= n and y >= 0 and y <= m and mat[x][y] != '#' and mat[x][y] != 'X') return 1;
- return 0;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int n, m, d;
- cin >> n >> m >> d;
- for(int i = 0; i < n; i++){
- string str;
- cin >> str;
- for(int j = 0; j < m; j++){
- mat[i][j] = str[j];
- }
- }
- bool br = 0;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < m; j++){
- if(d <= 0){
- br = 1;
- break;
- }
- if(mat[i][j] == '.'){
- mat[i][j] = 'X';
- bool ok = 1;
- //pair <int,int> cur = {i, j};
- //go to the neighbours of i ,j
- for(int k = 0; k < 4; k++){
- if(valid(i+dx[k], j+dy[k], n, m)){
- // check if it's blocked
- int curi = i+dx[k], curj = j+dy[k];
- bool blocked = 1;
- for(int l = 0; l < 4; l++){
- if(valid(curi + dx[l], curj + dy[l], n, m)){
- blocked = 0;
- break;
- }
- }
- if(blocked){
- ok = 0;
- break;
- }
- }
- }
- if(!ok){
- mat[i][j] = '.';
- }
- else{
- d--;
- }
- }
- }
- if(br) break;
- }
- for(int i = 0; i < n; i++){
- for(int j = 0; j < m; j++){
- cout << mat[i][j];
- }
- cout << endl;
- }
- cout << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment