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>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#define debugArr(...) 69
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N = 6e6 + 23;
const ll inf = 1e18;
#define F first
#define S second
#define pb push_back
#define kill(x) cout<<x<<endl, exit(0);
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lc (v << 1)
#define rc ((v<<1) |1)
int dx[] = {0,1,0,-1,1,1,-1,-1};
int dy[] = {1,0,-1,0,1,-1,-1,1};
int n,m,k;
bool check(pii p) {
return p.F >= 1 && p.F <= n && p.S >= 1 && p.S <= m;
}
vector<char> a[N];
vector<bool> mark[N];
vector<pii> sex;
queue<pii> Q;
void adj1(pii v) {
if(mark[v.F][v.S]) return;
if(a[v.F][v.S] == '#') {
sex.pb(v);
return;
}
mark[v.F][v.S] = true;
for(int i= 0 ;i <4; i ++) {
pii u = v;
u.F += dx[i];
u.S += dy[i];
if(check(u)) Q.push(u);
}
}
void adj2(pii v) {
if(mark[v.F][v.S]) return;
mark[v.F][v.S] = 1;
for(int i= 0; i < 8; i ++) {
pii u = v;
u.F += dx[i];
u.S += dy[i];
if(check(u)) {
sex.pb(u);
if(i < 4) Q.push(u);
}
}
}
vector<int> layer;
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n>>m>>k;
for(int i = 1; i <= n ;i ++) {
a[i].resize(m+1);
mark[i].resize(m+1);
}
int sx,sy,ex,ey; cin>>sx>>sy>>ex>>ey;
for(int i = 1; i <= n ;i ++) for(int j = 1;j <= m ; j ++) {
cin>>a[i][j];
}
int ans =0;
Q.push({sx,sy});
while(true) {
while(sz(Q)) {
pii v = Q.front(); Q.pop();
adj1(v);
}
if(mark[ex][ey]) break;
ans ++;
for(int i = 0 ;i< k ; i ++) {
vector<pii> nw = sex;
sex.clear();
for(pii x : nw) adj2(x);
}
sex.clear();
}
cout<<ans << '\n';
return 0;
}
// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!
# | 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... |