Submission #65666420
Source Code Expand
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n); i-- > 0;)
#define FOR(i, l, r) for(int i = (int)(l); i < (int)(r); ++i)
#define RFOR(i, r, l) for(int i = (int)(r); i-- > (int)(l);)
#define ALL(v) std::begin(v), std::end(v)
using llong = long long;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int, int>;
using namespace std;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr int MOD = 998'244'353;
constexpr int MOD2 = 1e9 + 7;
template <typename Type>
inline std::istream &operator>>(std::istream &is, std::vector<Type> &v) {
for(auto &elem : v) is >> elem;
return is;
}
template <typename Type>
inline std::ostream &operator<<(std::ostream &os, const std::vector<Type> &v) {
for(auto iter = v.cbegin(); iter != v.cend(); ++iter) os << (iter == v.cbegin() ? "" : " ") << *iter;
return os;
}
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...) static_cast<void>(0)
#endif
template <typename Type>
std::vector<Type> table(std::size_t n, const Type &val) { return std::vector<Type>(n, val); }
template <typename... Args>
auto table(std::size_t n, const Args &...args) { return std::vector(n, table(args...)); }
template <typename Type>
bool chmin(Type &a, const Type &b) {
if(a <= b) return false;
a = b;
return true;
}
template <typename Type>
bool chmax(Type &a, const Type &b) {
if(a >= b) return false;
a = b;
return true;
}
int main(){
int h,w;
cin>>h>>w;
vector<string> vs(h);
cin>>vs;
vector<pii> e;
REP(i,h)REP(j,w){
if(vs[i][j]=='E'){
e.emplace_back(i,j);
}
}
constexpr std::pair<int, int> dydx4[] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
auto is_inner = [&](int y, int x) -> bool {
return (0 <= y and y < h and 0 <= x and x < w);
};
auto &&dp=table(h,w,INF);
queue<pii> que;
for(auto [y,x]:e){
dp[y][x]=0;
que.emplace(y,x);
}
while(!que.empty()){
auto &&[y,x]=que.front();
que.pop();
for(const auto &[dy,dx]:dydx4){
const int ny=y+dy, nx=x+dx;
if(!is_inner(ny,nx) or vs[ny][nx]=='#') continue;
if(chmin(dp[ny][nx],dp[y][x]+1)) que.emplace(ny,nx);
}
}
debug(dp);
const string key="^<>v";
REP(i,h)REP(j,w){
if(vs[i][j]=='.'){
REP(k,4){
const auto &[dy,dx]=dydx4[k];
const int ny=i+dy, nx=j+dx;
if(!is_inner(ny,nx)) continue;
if(dp[ny][nx]==dp[i][j]-1){
vs[i][j]=key[k];
break;
}
}
}
}
for(auto s:vs) cout<<s<<"\n";
}
Submission Info
| Submission Time |
|
| Task |
D - Escape Route |
| User |
Today |
| Language |
C++ 23 (gcc 12.2) |
| Score |
400 |
| Code Size |
2962 Byte |
| Status |
AC |
| Exec Time |
48 ms |
| Memory |
17252 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_corner_00.txt, 02_corner_01.txt, 02_corner_02.txt, 02_corner_03.txt, 02_corner_04.txt, 02_corner_05.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3460 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3464 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3416 KiB |
| 01_random_00.txt |
AC |
29 ms |
12372 KiB |
| 01_random_01.txt |
AC |
24 ms |
8116 KiB |
| 01_random_02.txt |
AC |
44 ms |
13580 KiB |
| 01_random_03.txt |
AC |
38 ms |
10496 KiB |
| 01_random_04.txt |
AC |
28 ms |
9876 KiB |
| 01_random_05.txt |
AC |
32 ms |
9504 KiB |
| 01_random_06.txt |
AC |
33 ms |
12296 KiB |
| 01_random_07.txt |
AC |
43 ms |
11052 KiB |
| 01_random_08.txt |
AC |
23 ms |
14104 KiB |
| 01_random_09.txt |
AC |
22 ms |
7132 KiB |
| 01_random_10.txt |
AC |
32 ms |
9092 KiB |
| 01_random_11.txt |
AC |
48 ms |
15084 KiB |
| 01_random_12.txt |
AC |
45 ms |
16260 KiB |
| 01_random_13.txt |
AC |
37 ms |
10128 KiB |
| 01_random_14.txt |
AC |
34 ms |
10720 KiB |
| 01_random_15.txt |
AC |
42 ms |
11140 KiB |
| 02_corner_00.txt |
AC |
22 ms |
9332 KiB |
| 02_corner_01.txt |
AC |
15 ms |
9428 KiB |
| 02_corner_02.txt |
AC |
37 ms |
17252 KiB |
| 02_corner_03.txt |
AC |
1 ms |
3560 KiB |
| 02_corner_04.txt |
AC |
1 ms |
3564 KiB |
| 02_corner_05.txt |
AC |
30 ms |
9420 KiB |