이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
signed main(){
int dx[] = {-1, 1, 0, 0, -1, 1, -1, 1}; int dy[] = {0, 0, -1, 1, -1, 1, 1, -1};
int n, r, c; cin >> r >> c >> n;
int sr, sc; cin >> sr >> sc; sr--;sc--;
int gr, gc; cin >> gr >> gc; gr--;gc--;
vector<string> board(r);
for(auto &s : board) cin >> s;
vector<vector<int>> mark(r, vector<int>(c, 0));
queue<pair<int,int>> todo;
vector<pair<int,int>> funny;
auto good = [&](pair<int,int>p){
return p.ff>=0&&p.ss>=0&&p.ff< r&&p.ss<c;
};
auto ad = [&](pair<int,int> p){
if(mark[p.ff][p.ss]) return;
if(board[p.ff][p.ss]=='#'){
funny.push_back(p);
return;
}
mark[p.ff][p.ss] = 1;
for(int d = 0; d < 4; d++){
auto t = p; t.ff+=dx[d]; t.ss+=dy[d];
if(good(t)) todo.push(t);
}
};
auto ad2 = [&](pair<int,int> p){
if(mark[p.ff][p.ss]) return;
mark[p.ff][p.ss] = 1;
for(int d = 0; d < 8; d++){
auto t = p; t.ff+=dx[d]; t.ss+=dy[d];
if(good(t)) {
if(d<4)
todo.push(t);
funny.push_back(t);
}
}
};
ad({sr, sc});
int res = 0;
for(;;){
while(!todo.empty()){
ad(todo.front());
todo.pop();
}
if(mark[gr][gc]) break;
res++;
//do funny thing
for(int i = 0; i < n; i++){
auto tmp = funny; funny.clear();
for(auto &x : tmp){
ad2(x);
}
}
}
cout<<res<<endl;
}
# | 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... |