提出 #65676300


ソースコード 拡げる

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
// using mint = modint998244353;

/* alias*/
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvd = vector<vd>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpi = vector<pii>;
using vpl = vector<pll>;
using ql = queue<ll>;
using qpl = queue<pll>;
using si = set<int>;
using sl = set<ll>;
using ss = set<string>;
using sd = set<double>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using msl = map<string, ll>;
using mls = map<ll, string>;

/* define short */
#define _overload5(a, b, c, d, e, name, ...) name
#define _overload4(a, b, c, d, name, ...) name
#define _overload3(a, b, c, name, ...) name
#define _rep0(n) for (ll i = 0; i < (ll)(n); ++i)
#define _rep1(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define _rep2(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define _rep3(i, a, b, c) for (ll i = (ll)(a); i < (ll)(b); i += (ll)(c))
#define rep(...) _overload4(__VA_ARGS__, _rep3, _rep2, _rep1, _rep0)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n) - 1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep4(i, a, b, c) for (ll i = (a) + ((b) - (a) - 1) / (c) * (c); i >= (a); i -= c)
#define rrep(...) _overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define join(a, b) a.insert(a.end(), ALL(b))
#define vsort(a) sort(all(a))
#define sz(x) (ll)(x).size()
#define pcnt(x) __builtin_popcountll(x)
#define eb emplace_back
#define fi first
#define se second

/* debug */
// 標準エラー出力を含む提出はrejectされる場合もあるので注意
#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl;

/* const */
const int INF = INT_MAX / 2;
const ll LINF = 1LL << 60;
const int dx4[]{1, 0, -1, 0, 0};
const int dy4[]{0, 1, 0, -1, 0};
const int dx8[]{1, 1, 0, -1, -1, -1, 0, 1, 0};
const int dy8[]{0, 1, 1, 1, 0, -1, -1, -1, 0};
const char PASSAGE = '.';
const char WALL = '#';
const double PI = 3.1415926535;
const string YES = "Yes";
const string NO = "No";
const ll MOD = 1e5;
// const int MOD = 998244353;

/* func */
template <class T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <class T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
inline void yes() { cout << YES << endl; }
inline void no() { cout << NO << endl; }
template <class T>
inline void out(T a) { cout << a << endl; }
template <class T>
inline void vout(T a, bool b)
{
    rep(i, sz(a))
    {
        cout << a[i];
        b ? cout << " " : cout << endl;
    }
    if (b)
        cout << endl;
}

ll h, w;
ll start_y, start_x, goal_y, goal_x;
vs maze;
vs seen;
qpl que;

ll countElement(char c)
{
    ll sum = 0;
    rep(y, h)
    {
        rep(x, w)
        {
            if (maze[y][x] == c)
                sum++;
        }
    }
    return sum;
}
// マップの範囲判定
bool checkOutOfRange(ll y, ll x)
{
    return y < 0 || y >= h || x < 0 || x >= w;
}

bool checkWall(ll y, ll x)
{
    return maze[y][x] == WALL;
}

void bfsMaze()
{
    while (!que.empty())
    {
        auto [now_y, now_x] = que.front();
        que.pop();

        rep(i, 4)
        {
            ll next_y = now_y + dy4[i];
            ll next_x = now_x + dx4[i];

            // 移動した先が[迷路の範囲外である]場合は処理をスキップ
            if (checkOutOfRange(next_y, next_x))
                continue;
            // 移動した先が[壁である]場合は処理をスキップ
            if (checkWall(next_y, next_x))
                continue;
            // 移動した先が[探索済である] 場合は処理をスキップ
            if (seen[next_y][next_x] != '.')
                continue;

            // 処理
            // 左から右へ移動
            if (now_y == next_y && now_x == next_x - 1)
                seen[next_y][next_x] = '<';
            // 右から左へ移動
            if (now_y == next_y && now_x - 1 == next_x)
                seen[next_y][next_x] = '>';
            // 上から下へ移動
            if (now_y == next_y - 1 && now_x == next_x)
                seen[next_y][next_x] = '^';
            // 下から上へ移動
            if (now_y - 1 == next_y && now_x == next_x)
                seen[next_y][next_x] = 'v';
            // seen[next_y][next_x] = seen[now_y][now_x] + 1;
            que.push({next_y, next_x});
        }
    }
}

void setMaze()
{
    cin >> h >> w;

    // スタート地点、ゴール地点が指定されている場合
    // cin >> start_y >> start_x;
    // cin >> goal_y >> goal_x;
    // start_y--;
    // start_x--;
    // goal_y--;
    // goal_x--;

    // seenを初期化(通常は-1)
    // vector<ll> v(w, -1);
    rep(i, h)
    {
        string str;
        cin >> str;
        maze.push_back(str);
        seen.push_back(str);
    }
}

// y : 上下方向
// x : 左右方向
int main(void)
{
    // 入力を受ける
    setMaze();

    // スタート地点、ゴール地点が指定されていない場合は自分で設定
    // start_y = 0;
    // start_x = 0;
    // goal_y = h - 1;
    // goal_x = w - 1;

    // スタート地点を設定 (スタート地点を含める場合は1、含めない場合は0)
    rep(start_y, h)
    {
        rep(start_x, w)
        {
            if (maze[start_y][start_x] == 'E')
            {
                // seen[start_y][start_x] = 0;
                que.push({start_y, start_x});
            }
        }
    }

    // 迷路を幅優先探索で探索
    bfsMaze();

    rep(i, h)
    {
        cout << seen[i] << endl;
    }

    return 0;
}

提出情報

提出日時
問題 D - Escape Route
ユーザ maeda__1221
言語 C++ 23 (gcc 12.2)
得点 400
コード長 6255 Byte
結果 AC
実行時間 40 ms
メモリ 13752 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 25
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3512 KiB
00_sample_01.txt AC 1 ms 3528 KiB
00_sample_02.txt AC 1 ms 3660 KiB
01_random_00.txt AC 25 ms 10600 KiB
01_random_01.txt AC 22 ms 7508 KiB
01_random_02.txt AC 38 ms 12208 KiB
01_random_03.txt AC 33 ms 7368 KiB
01_random_04.txt AC 25 ms 9520 KiB
01_random_05.txt AC 28 ms 9036 KiB
01_random_06.txt AC 26 ms 9988 KiB
01_random_07.txt AC 37 ms 9072 KiB
01_random_08.txt AC 22 ms 12220 KiB
01_random_09.txt AC 20 ms 5072 KiB
01_random_10.txt AC 28 ms 6864 KiB
01_random_11.txt AC 40 ms 13664 KiB
01_random_12.txt AC 38 ms 13752 KiB
01_random_13.txt AC 32 ms 6992 KiB
01_random_14.txt AC 29 ms 9604 KiB
01_random_15.txt AC 36 ms 9080 KiB
02_corner_00.txt AC 22 ms 5628 KiB
02_corner_01.txt AC 15 ms 5636 KiB
02_corner_02.txt AC 37 ms 13340 KiB
02_corner_03.txt AC 1 ms 3580 KiB
02_corner_04.txt AC 2 ms 3656 KiB
02_corner_05.txt AC 25 ms 5524 KiB