提出 #68750198


ソースコード 拡げる

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
/* vector用 */
template <class T>
struct std::hash<std::vector<T>>
{
    size_t operator()(const std::vector<T> &keyval) const noexcept
    {
        size_t s = 0;
        for (auto &&v : keyval)
            s = HashCombine(s, v);
        return s;
    }
};
/* tuple用 */
template <int N>
struct HashTupleCore
{
    template <class Tuple>
    size_t operator()(const Tuple &keyval) const noexcept
    {
        size_t s = HashTupleCore<N - 1>()(keyval);
        return HashCombine(s, std::get<N - 1>(keyval));
    }
};
template <>
struct HashTupleCore<0>
{
    template <class Tuple>
    size_t operator()(const Tuple &keyval) const noexcept { return 0; }
};
template <class... Args>
struct std::hash<std::tuple<Args...>>
{
    size_t operator()(const tuple<Args...> &keyval) const noexcept
    {
        return HashTupleCore<tuple_size<tuple<Args...>>::value>()(keyval);
    }
};
////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h)
    {
        cin >> s[i];
    }
    ll sx, sy, gx, gy;
    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            if (s[i][j] == 'S')
            {
                sx = i;
                sy = j;
            }
            if (s[i][j] == 'G')
            {
                gx = i;
                gy = j;
            }
        }
    }
    queue<pair<pair<ll, ll>, ll>> que;
    vector<vector<vector<ll>>> d(h, vector<vector<ll>>(w, vector<ll>(2, inf)));
    d[sx][sy][0] = 0;
    que.push(pr(pr(sx, sy), 0));
    vector<ll> dx = {1, 0, -1, 0};
    vector<ll> dy = {0, -1, 0, 1};
    while (!que.empty())
    {
        ll x = que.front().first.first;
        ll y = que.front().first.second;
        ll f = que.front().second;
        que.pop();
        rep(i, 0, 4)
        {
            ll nx = x + dx[i];
            ll ny = y + dy[i];
            if (isin(nx, 0, h) && isin(ny, 0, w))
            {
                if (s[nx][ny] == '#')
                {
                    continue;
                }
                if (s[nx][ny] == '?')
                {
                    if (d[nx][ny][1 - f] > 1 + d[x][y][f])
                    {
                        d[nx][ny][1 - f] = 1 + d[x][y][f];
                        que.push(pr(pr(nx, ny), 1 - f));
                    }
                }
                else
                {
                    if (s[nx][ny] == 'o' && f == 1)
                    {
                        continue;
                    }
                    if (s[nx][ny] == 'x' && f == 0)
                    {
                        continue;
                    }
                    if (d[nx][ny][f] > 1 + d[x][y][f])
                    {
                        d[nx][ny][f] = 1 + d[x][y][f];
                        que.push(pr(pr(nx, ny), f));
                    }
                }
            }
        }
    }
    ll ans = min(d[gx][gy][0], d[gx][gy][1]);
    if (ans == inf)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

提出情報

提出日時
問題 D - Toggle Maze
ユーザ a_s_k
言語 C++ 23 (gcc 12.2)
得点 400
コード長 5329 Byte
結果 AC
実行時間 49 ms
メモリ 17644 KiB

コンパイルエラー

In file included from /usr/include/c++/12/bits/stl_algobase.h:64,
                 from /usr/include/c++/12/bits/specfun.h:45,
                 from /usr/include/c++/12/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:41,
                 from Main.cpp:1:
In constructor ‘constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U1 = std::pair<long long int, long long int>; _U2 = int; _T1 = std::pair<long long int, long long int>; _T2 = long long int]’,
    inlined from ‘int main()’ at Main.cpp:137:13:
/usr/include/c++/12/bits/stl_pair.h:299:11: warning: ‘sy’ may be used uninitialized [-Wmaybe-uninitialized]
  299 |         : first(std::forward<_U1>(__p.first)),
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:117:12: note: ‘sy’ was declared here
  117 |     ll sx, sy, gx, gy;
      |            ^~
In constructor ‘constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U1 = std::pair<long long int, long long int>; _U2 = int; _T1 = std::pair<long long int, long long int>; _T2 = long long int]’,
    inlined from ‘int main()’ at Main.cpp:137:13:
/usr/include/c++/12/bits/stl_pair.h:299:11: warning: ‘sx’ may be used uninitialized [-Wmaybe-uninitialized]
  299 |         : first(std::forward<_U1>(__p.first)),
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:117:8: note: ‘sx’ was declared here
  117 |     ll sx, sy, gx, gy;
      |        ^~
Main.cpp:183:40: warning: ‘gy’ may be used uninitialized [-Wmaybe-uninitialized]
  183 |     ll ans = min(d[gx][gy][0], d[gx][gy][1]);
      |                                        ^
Main.cpp:117:20: note: ‘gy’ was declared here
  117 |     ll sx, sy, gx, gy;
      |                    ^~
Main.cpp:183:36: warning: ‘gx’ may be used uninitialized [-Wmaybe-uninitialized]
  183 |     ll ans = min(d[gx][gy][0], d[gx][gy][1]);
      |                                    ^
Main.cpp:117:16: note: ‘gx’ was declared here
  117 |     ll sx, sy, gx, gy;
      |                ^~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 67
セット名 テストケース
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_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 02_random_32.txt, 02_random_33.txt, 02_random_34.txt, 02_random_35.txt, 02_random_36.txt, 02_random_37.txt, 02_random_38.txt, 02_random_39.txt, 02_random_40.txt, 02_random_41.txt, 02_random_42.txt, 02_random_43.txt, 02_random_44.txt, 02_random_45.txt, 02_random_46.txt, 02_random_47.txt, 02_random_48.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3512 KiB
00_sample_01.txt AC 1 ms 3520 KiB
00_sample_02.txt AC 1 ms 3444 KiB
01_handmade_00.txt AC 35 ms 17492 KiB
01_handmade_01.txt AC 34 ms 17448 KiB
01_handmade_02.txt AC 34 ms 17512 KiB
01_handmade_03.txt AC 34 ms 17516 KiB
01_handmade_04.txt AC 1 ms 3404 KiB
01_handmade_05.txt AC 1 ms 3516 KiB
01_handmade_06.txt AC 1 ms 3436 KiB
01_handmade_07.txt AC 1 ms 3516 KiB
01_handmade_08.txt AC 1 ms 3500 KiB
01_handmade_09.txt AC 16 ms 17428 KiB
01_handmade_10.txt AC 17 ms 17348 KiB
01_handmade_11.txt AC 35 ms 17600 KiB
01_handmade_12.txt AC 36 ms 17444 KiB
01_handmade_13.txt AC 32 ms 17432 KiB
01_handmade_14.txt AC 32 ms 17508 KiB
02_random_00.txt AC 1 ms 3640 KiB
02_random_01.txt AC 26 ms 13776 KiB
02_random_02.txt AC 2 ms 4132 KiB
02_random_03.txt AC 30 ms 15516 KiB
02_random_04.txt AC 2 ms 5124 KiB
02_random_05.txt AC 34 ms 17508 KiB
02_random_06.txt AC 28 ms 15332 KiB
02_random_07.txt AC 33 ms 17408 KiB
02_random_08.txt AC 4 ms 7004 KiB
02_random_09.txt AC 34 ms 17460 KiB
02_random_10.txt AC 12 ms 17380 KiB
02_random_11.txt AC 34 ms 17516 KiB
02_random_12.txt AC 12 ms 17436 KiB
02_random_13.txt AC 8 ms 6472 KiB
02_random_14.txt AC 29 ms 14604 KiB
02_random_15.txt AC 2 ms 3848 KiB
02_random_16.txt AC 35 ms 17520 KiB
02_random_17.txt AC 2 ms 3976 KiB
02_random_18.txt AC 36 ms 17440 KiB
02_random_19.txt AC 3 ms 4348 KiB
02_random_20.txt AC 35 ms 17516 KiB
02_random_21.txt AC 1 ms 3608 KiB
02_random_22.txt AC 35 ms 17644 KiB
02_random_23.txt AC 2 ms 4040 KiB
02_random_24.txt AC 13 ms 12936 KiB
02_random_25.txt AC 5 ms 8260 KiB
02_random_26.txt AC 12 ms 8856 KiB
02_random_27.txt AC 5 ms 5864 KiB
02_random_28.txt AC 22 ms 17396 KiB
02_random_29.txt AC 8 ms 7360 KiB
02_random_30.txt AC 30 ms 17344 KiB
02_random_31.txt AC 11 ms 14588 KiB
02_random_32.txt AC 17 ms 17440 KiB
02_random_33.txt AC 12 ms 10168 KiB
02_random_34.txt AC 23 ms 17576 KiB
02_random_35.txt AC 8 ms 5612 KiB
02_random_36.txt AC 27 ms 11500 KiB
02_random_37.txt AC 18 ms 8520 KiB
02_random_38.txt AC 49 ms 17464 KiB
02_random_39.txt AC 39 ms 15236 KiB
02_random_40.txt AC 46 ms 17524 KiB
02_random_41.txt AC 1 ms 3552 KiB
02_random_42.txt AC 1 ms 3556 KiB
02_random_43.txt AC 1 ms 3620 KiB
02_random_44.txt AC 1 ms 3500 KiB
02_random_45.txt AC 1 ms 3496 KiB
02_random_46.txt AC 1 ms 3724 KiB
02_random_47.txt AC 1 ms 3628 KiB
02_random_48.txt AC 1 ms 3632 KiB