Submission #64544332
Source Code Expand
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) begin(v), end(v)
#define pi pair<int, int>
#define vi vector<int>
using namespace std;
const int N = 1e3+5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int n, m;
char a[N][N];
int D[N][N];
bool bound(int x, int y){
return x >= 1 && y >= 1 && x <= n && y <= m;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
int u, v;
cin >> u >> v;
memset(D, 0x3f, sizeof(D));
D[u][v] = 0;
deque<pi> q;
q.push_front({u, v});
while(!q.empty()){
int x = (q.front()).first, y = (q.front()).second;
q.pop_front();
for(int d = 0; d < 4; d++){
int z = x+dx[d], t = y+dy[d];
if(bound(z, t) && a[z][t] != '#'){
if(D[z][t] > D[x][y]){
D[z][t] = D[x][y];
q.push_front({z, t});
}
}
}
for(int M = 1; M <= 2; M++){
for(int d = 0; d < 4; d++){
int z = x+dx[d]*M, t = y+dy[d]*M;
if(bound(z, t)){
if(D[z][t] > D[x][y] + 1){
D[z][t] = D[x][y] + 1;
q.push_back({z, t});
}
}
}
}
}
cin >> u >> v;
cout << D[u][v];
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Takahashi the Wall Breaker |
| User | reginox |
| Language | C++ 20 (gcc 12.2) |
| Score | 400 |
| Code Size | 1363 Byte |
| Status | AC |
| Exec Time | 82 ms |
| Memory | 16504 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt, example_02.txt, example_03.txt |
| All | example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 3 ms | 7372 KiB |
| example_01.txt | AC | 2 ms | 7428 KiB |
| example_02.txt | AC | 2 ms | 7476 KiB |
| example_03.txt | AC | 3 ms | 7372 KiB |
| hand_00.txt | AC | 38 ms | 8476 KiB |
| hand_01.txt | AC | 42 ms | 8392 KiB |
| hand_02.txt | AC | 41 ms | 8448 KiB |
| hand_03.txt | AC | 37 ms | 8440 KiB |
| hand_04.txt | AC | 39 ms | 8384 KiB |
| hand_05.txt | AC | 48 ms | 12528 KiB |
| hand_06.txt | AC | 47 ms | 12596 KiB |
| hand_07.txt | AC | 60 ms | 16504 KiB |
| hand_08.txt | AC | 59 ms | 16428 KiB |
| hand_09.txt | AC | 2 ms | 7272 KiB |
| random_00.txt | AC | 41 ms | 8268 KiB |
| random_01.txt | AC | 42 ms | 8392 KiB |
| random_02.txt | AC | 47 ms | 8324 KiB |
| random_03.txt | AC | 47 ms | 8340 KiB |
| random_04.txt | AC | 35 ms | 8324 KiB |
| random_05.txt | AC | 38 ms | 8292 KiB |
| random_06.txt | AC | 82 ms | 14072 KiB |
| random_07.txt | AC | 80 ms | 14464 KiB |
| random_08.txt | AC | 76 ms | 16064 KiB |
| random_09.txt | AC | 79 ms | 14160 KiB |
| random_10.txt | AC | 76 ms | 14216 KiB |
| random_11.txt | AC | 81 ms | 14080 KiB |
| random_12.txt | AC | 62 ms | 8404 KiB |
| random_13.txt | AC | 72 ms | 8400 KiB |
| random_14.txt | AC | 58 ms | 8332 KiB |
| random_15.txt | AC | 62 ms | 8424 KiB |
| random_16.txt | AC | 72 ms | 8572 KiB |
| random_17.txt | AC | 40 ms | 8396 KiB |
| random_18.txt | AC | 46 ms | 8440 KiB |
| random_19.txt | AC | 40 ms | 8420 KiB |