This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#define endl "\n"
#define sp " "
#define MOD 1000000007
#define f1(i, x) for(auto &i : x)
#define f2(i, x, j) for(ll i = j; i < x; i++)
#define raya() cout << endl << "====================================" << endl
#define dbg(x) cerr << #x << ": " << x << endl;
#define INF LLONG_MAX
using namespace std;
typedef long long ll;
vector<vector<bool>> vis;
ll n, m;
bool check_neighbours(ll i, ll j){
if(i == n or j == m) return 0;
ll ans = 0;
if(i > 0) ans += vis[i - 1][j];
if(i < n - 1) ans += vis[i + 1][j];
if(j > 0) ans += vis[i][j - 1];
if(j < m - 1) ans += vis[i][j + 1];
return ans == 1 and !vis[i][j];
}
bool change_neighbours(ll i, ll j){
bool t = false;
if(check_neighbours(i, j + 1)){
vis[i][j + 1] = 1;
t = true;
}
if(check_neighbours(i, j - 1)){
vis[i][j - 1] = 1;
t = true;
}
if(check_neighbours(i + 1, j)){
vis[i + 1][j] = 1;
t = true;
}
if(check_neighbours(i - 1, j)) {
vis[i - 1][j] = 1;
t = true;
}
return t;
}
void solve(){
ll k;
cin >> n >> m >> k;
vector<vector<char>> arr(n, vector<char>(m)), ans(n, vector<char>(m, 'X'));
vis.resize(n, vector<bool>(m));
bool x = true;
f1(i, arr){
f1(j, i){
cin >> j;
if(j == '#') x = false;
}
}
if(x){
bool l;
vis[1][1] = true;
do {
l = 0;
for(int i = 1; i < n; i++)
for(int j = 1; j < m; j++)
if(change_neighbours(i, j))
l = 1;
} while(l);
}
f2(i, n, 0){
f2(j, m, 0){
if(vis[i][j]) ans[i][j] = '.';
cout << ans[i][j];
}
cout << endl;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie();
cout.tie();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |