結果

問題 No.5006 Hidden Maze
ユーザー komori3komori3
提出日時 2022-06-12 18:42:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 10,998 bytes
コンパイル時間 3,798 ms
実行使用メモリ 22,728 KB
スコア 66,645
平均クエリ数 334.55
最終ジャッジ日時 2022-06-12 18:43:14
合計ジャッジ時間 13,245 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
22,408 KB
testcase_01 AC 30 ms
22,228 KB
testcase_02 AC 25 ms
21,904 KB
testcase_03 AC 41 ms
22,552 KB
testcase_04 AC 35 ms
21,892 KB
testcase_05 AC 56 ms
21,844 KB
testcase_06 AC 35 ms
21,772 KB
testcase_07 AC 102 ms
22,408 KB
testcase_08 AC 111 ms
22,564 KB
testcase_09 AC 83 ms
22,228 KB
testcase_10 AC 32 ms
21,928 KB
testcase_11 AC 24 ms
22,456 KB
testcase_12 AC 31 ms
21,940 KB
testcase_13 AC 29 ms
22,728 KB
testcase_14 AC 38 ms
21,780 KB
testcase_15 AC 23 ms
21,768 KB
testcase_16 AC 46 ms
21,780 KB
testcase_17 AC 34 ms
21,792 KB
testcase_18 AC 40 ms
22,576 KB
testcase_19 AC 101 ms
22,552 KB
testcase_20 AC 33 ms
22,240 KB
testcase_21 AC 24 ms
21,744 KB
testcase_22 AC 26 ms
21,780 KB
testcase_23 AC 26 ms
22,192 KB
testcase_24 AC 37 ms
22,632 KB
testcase_25 AC 24 ms
22,560 KB
testcase_26 AC 52 ms
22,216 KB
testcase_27 AC 21 ms
22,632 KB
testcase_28 AC 51 ms
22,576 KB
testcase_29 AC 95 ms
22,456 KB
testcase_30 AC 21 ms
21,892 KB
testcase_31 AC 21 ms
21,772 KB
testcase_32 AC 59 ms
21,892 KB
testcase_33 AC 70 ms
21,992 KB
testcase_34 AC 26 ms
21,792 KB
testcase_35 AC 82 ms
21,856 KB
testcase_36 AC 110 ms
21,892 KB
testcase_37 AC 100 ms
21,904 KB
testcase_38 AC 108 ms
22,228 KB
testcase_39 AC 18 ms
21,768 KB
testcase_40 AC 18 ms
21,904 KB
testcase_41 AC 27 ms
21,792 KB
testcase_42 AC 34 ms
21,952 KB
testcase_43 AC 35 ms
21,856 KB
testcase_44 AC 20 ms
21,672 KB
testcase_45 AC 50 ms
21,780 KB
testcase_46 AC 76 ms
21,768 KB
testcase_47 AC 44 ms
21,904 KB
testcase_48 AC 109 ms
22,528 KB
testcase_49 AC 116 ms
21,916 KB
testcase_50 AC 33 ms
22,004 KB
testcase_51 AC 47 ms
22,016 KB
testcase_52 AC 32 ms
21,756 KB
testcase_53 AC 43 ms
22,016 KB
testcase_54 AC 18 ms
22,204 KB
testcase_55 AC 37 ms
21,904 KB
testcase_56 AC 34 ms
22,420 KB
testcase_57 AC 41 ms
21,904 KB
testcase_58 AC 89 ms
21,940 KB
testcase_59 AC 23 ms
21,904 KB
testcase_60 AC 20 ms
22,004 KB
testcase_61 AC 15 ms
22,524 KB
testcase_62 AC 19 ms
21,992 KB
testcase_63 AC 36 ms
21,868 KB
testcase_64 AC 20 ms
21,940 KB
testcase_65 AC 31 ms
22,576 KB
testcase_66 AC 112 ms
21,916 KB
testcase_67 AC 101 ms
22,228 KB
testcase_68 AC 82 ms
22,504 KB
testcase_69 AC 89 ms
21,928 KB
testcase_70 AC 21 ms
21,964 KB
testcase_71 AC 24 ms
22,564 KB
testcase_72 AC 32 ms
21,968 KB
testcase_73 AC 67 ms
22,192 KB
testcase_74 AC 52 ms
21,792 KB
testcase_75 AC 44 ms
21,940 KB
testcase_76 AC 19 ms
22,204 KB
testcase_77 AC 68 ms
22,644 KB
testcase_78 AC 39 ms
22,516 KB
testcase_79 AC 104 ms
21,904 KB
testcase_80 AC 21 ms
21,904 KB
testcase_81 AC 25 ms
22,564 KB
testcase_82 AC 27 ms
22,588 KB
testcase_83 AC 19 ms
21,916 KB
testcase_84 AC 34 ms
22,192 KB
testcase_85 AC 41 ms
21,756 KB
testcase_86 AC 27 ms
22,516 KB
testcase_87 AC 96 ms
22,516 KB
testcase_88 AC 62 ms
22,552 KB
testcase_89 AC 117 ms
21,904 KB
testcase_90 AC 23 ms
21,772 KB
testcase_91 AC 28 ms
22,584 KB
testcase_92 AC 37 ms
21,904 KB
testcase_93 AC 26 ms
22,704 KB
testcase_94 AC 23 ms
21,904 KB
testcase_95 AC 48 ms
21,904 KB
testcase_96 AC 36 ms
21,880 KB
testcase_97 AC 108 ms
21,968 KB
testcase_98 AC 110 ms
21,880 KB
testcase_99 AC 22 ms
21,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <unordered_set>
#include <atcoder/all>
//#include <boost/rational.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_bin_float.hpp>
#ifdef _MSC_VER
#include <conio.h>
#include <ppl.h>
#include <filesystem>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <intrin.h>
int __builtin_clz(unsigned int n)
{
    unsigned long index;
    _BitScanReverse(&index, n);
    return 31 - index;
}
int __builtin_ctz(unsigned int n)
{
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
}
namespace std {
    inline int __lg(int __n) { return sizeof(int) * 8 - 1 - __builtin_clz(__n); }
}
#else
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

/** compro_io **/

/* tuple */
// out
namespace aux {
    template<typename T, unsigned N, unsigned L>
    struct tp {
        static void output(std::ostream& os, const T& v) {
            os << std::get<N>(v) << ", ";
            tp<T, N + 1, L>::output(os, v);
        }
    };
    template<typename T, unsigned N>
    struct tp<T, N, N> {
        static void output(std::ostream& os, const T& v) { os << std::get<N>(v); }
    };
}
template<typename... Ts>
std::ostream& operator<<(std::ostream& os, const std::tuple<Ts...>& t) {
    os << '[';
    aux::tp<std::tuple<Ts...>, 0, sizeof...(Ts) - 1>::output(os, t);
    return os << ']';
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& os, const Container& x);

/* pair */
// out
template<class S, class T>
std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
    return os << "[" << p.first << ", " << p.second << "]";
}
// in
template<class S, class T>
std::istream& operator>>(std::istream& is, std::pair<S, T>& p) {
    return is >> p.first >> p.second;
}

/* container */
// out
template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& os, const Container& x) {
    bool f = true;
    os << "[";
    for (auto& y : x) {
        os << (f ? "" : ", ") << y;
        f = false;
    }
    return os << "]";
}
// in
template <
    class T,
    class = decltype(std::begin(std::declval<T&>())),
    class = typename std::enable_if<!std::is_same<T, std::string>::value>::type
>
std::istream& operator>>(std::istream& is, T& a) {
    for (auto& x : a) is >> x;
    return is;
}

std::ostream& operator<<(std::ostream& os, const std::vector<bool>& v) {
    std::string s(v.size(), ' ');
    for (int i = 0; i < v.size(); i++) s[i] = v[i] + '0';
    os << s;
    return os;
}

std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<bool>>& m) {
    for (const auto& v : m) os << v << '\n';
    return os;
}

/* struct */
template<typename T>
auto operator<<(std::ostream& out, const T& t) -> decltype(out << t.stringify()) {
    out << t.stringify();
    return out;
}

/* setup */
struct IOSetup {
    IOSetup(bool f) {
        if (f) { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }
        std::cout << std::fixed << std::setprecision(15);
    }
} iosetup(true);

/** string formatter **/
template<typename... Ts>
std::string format(const std::string& f, Ts... t) {
    size_t l = std::snprintf(nullptr, 0, f.c_str(), t...);
    std::vector<char> b(l + 1);
    std::snprintf(&b[0], l + 1, f.c_str(), t...);
    return std::string(&b[0], &b[0] + l);
}

template<typename T>
std::string stringify(const T& x) {
    std::ostringstream oss;
    oss << x;
    return oss.str();
}

/* dump */
#define DUMPOUT std::cerr
std::ostringstream DUMPBUF;
#define dump(...) do{DUMPBUF<<"  ";DUMPBUF<<#__VA_ARGS__<<" :[DUMP - "<<__LINE__<<":"<<__FUNCTION__<<"]"<<std::endl;DUMPBUF<<"    ";dump_func(__VA_ARGS__);DUMPOUT<<DUMPBUF.str();DUMPBUF.str("");DUMPBUF.clear();}while(0);
void dump_func() { DUMPBUF << std::endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPBUF << head; if (sizeof...(Tail) == 0) { DUMPBUF << " "; } else { DUMPBUF << ", "; } dump_func(std::move(tail)...); }

/* timer */
class Timer {
    double t = 0, paused = 0, tmp;
public:
    Timer() { reset(); }
    static double time() {
#ifdef _MSC_VER
        return __rdtsc() / 3.0e9;
#else
        unsigned long long a, d;
        __asm__ volatile("rdtsc"
            : "=a"(a), "=d"(d));
        return (d << 32 | a) / 3.0e9;
#endif
    }
    void reset() { t = time(); }
    void pause() { tmp = time(); }
    void restart() { paused += time() - tmp; }
    double elapsed_ms() const { return (time() - t - paused) * 1000.0; }
};

/* rand */
struct Xorshift {
    uint64_t x = 88172645463325252LL;
    void set_seed(unsigned seed, int rep = 100) { x = uint64_t((seed + 1) * 10007); for (int i = 0; i < rep; i++) next_int(); }
    unsigned next_int() { x = x ^ (x << 7); return x = x ^ (x >> 9); }
    unsigned next_int(unsigned mod) { x = x ^ (x << 7); x = x ^ (x >> 9); return x % mod; }
    unsigned next_int(unsigned l, unsigned r) { x = x ^ (x << 7); x = x ^ (x >> 9); return x % (r - l + 1) + l; } // inclusive
    double next_double() { return double(next_int()) / UINT_MAX; }
} rnd;

/* shuffle */
template<typename T>
void shuffle_vector(std::vector<T>& v, Xorshift& rnd) {
    int n = v.size();
    for (int i = n - 1; i >= 1; i--) {
        int r = rnd.next_int(i);
        std::swap(v[i], v[r]);
    }
}

/* split */
std::vector<std::string> split(std::string str, const std::string& delim) {
    for (char& c : str) if (delim.find(c) != std::string::npos) c = ' ';
    std::istringstream iss(str);
    std::vector<std::string> parsed;
    std::string buf;
    while (iss >> buf) parsed.push_back(buf);
    return parsed;
}

template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}

template<typename T, typename ...Args> auto make_vector(T x, int arg, Args ...args) { if constexpr (sizeof...(args) == 0)return std::vector<T>(arg, x); else return std::vector(arg, make_vector<T>(x, args...)); }
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using ld = double;
//using ld = boost::multiprecision::cpp_bin_float_quad;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using namespace std;



template<typename T>
void print_vector(const vector<T>& v) {
    for (int i = 0; i < v.size(); i++) {
        cout << (i ? " " : "") << v[i];
    }
    cout << '\n';
}

constexpr int di[] = { 0, -1, 0, 1 };
constexpr int dj[] = { -1, 0, 1, 0 };
const string d2c = "LURD";
char c2d[256];

constexpr int N = 20, T = 1000;
constexpr int min_wall = 100, max_wall = 200;
constexpr double init_wall_prob = (min_wall + max_wall) * 0.5 / (N * (N - 1) * 2);
constexpr int si = 0, sj = 0, ti = N - 1, tj = N - 1;
constexpr double inf = 1e9, eps = 1e-8;
double fail_prob;

int main() {

    { 
        int buf;
        cin >> buf >> buf >> buf;
        fail_prob = buf / 100.0;
        c2d['L'] = 0; c2d['U'] = 1; c2d['R'] = 2; c2d['D'] = 3;
    }

    double  hspace[N][N - 1];
    double  vspace[N - 1][N];

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 1; j++) {
            hspace[i][j] = vspace[j][i] = 1.0 - init_wall_prob;
        }
    }

    auto get_cost = [&](int i, int j, int d) {
        double cost = -1.0;
        if (d == 0) cost = -1.0 * log(hspace[i][j - 1] < eps ? eps : hspace[i][j - 1]);
        if (d == 1) cost = -1.0 * log(vspace[i - 1][j] < eps ? eps : vspace[i - 1][j]);
        if (d == 2) cost = -1.0 * log(hspace[i][j] < eps ? eps : hspace[i][j]);
        if (d == 3) cost = -1.0 * log(vspace[i][j] < eps ? eps : vspace[i][j]);
        return max(0.0, cost);
    };

    // (ti,tj) まで最も壁っぽくなさそうなルートで移動する
    auto guess = [&]() {
        double dist[N][N];
        int prev[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dist[i][j] = inf;
                prev[i][j] = -1;
            }
        }
        using Edge = tuple<double, int, int>;
        priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
        dist[si][sj] = 0;
        pq.emplace(dist[si][sj], si, sj);
        while (!pq.empty()) {
            auto [mincost, i, j] = pq.top(); pq.pop();
            if (dist[i][j] < mincost) continue;
            for (int d = 0; d < 4; d++) {
                int ni = i + di[d], nj = j + dj[d];
                if (ni < 0 || ni >= N || nj < 0 || nj >= N) continue;
                double cost = dist[i][j] + get_cost(i, j, d);
                if (chmin(dist[ni][nj], cost)) {
                    dist[ni][nj] = cost;
                    prev[ni][nj] = d;
                    pq.emplace(cost, ni, nj);
                }
            }
        }
        string path;
        {
            int i = ti, j = tj, d = prev[i][j];
            while (d != -1) {
                path += d2c[d];
                i -= di[d];
                j -= dj[d];
                d = prev[i][j];
            }
            reverse(path.begin(), path.end());
        }
        return path;
    };

    auto update = [&](const string& g, const int length) {
        assert(length < g.size()); // equal なら終了しているはず
        int i = 0, j = 0;
        for (int k = 0; k < length; k++) {
            int d = c2d[g[k]], ni = i + di[d], nj = j + dj[d];
            // (i,j)-(ni,nj) に壁はない
            if (d == 0) hspace[i][j - 1] = 1.0;
            if (d == 1) vspace[i - 1][j] = 1.0;
            if (d == 2) hspace[i][j] = 1.0;
            if (d == 3) vspace[i][j] = 1.0;
            i = ni; j = nj;
        }
        {
            int d = c2d[g[length]], ni = i + di[d], nj = j + dj[d];
            // (i,j)-(ni,nj) は壁の可能性がある
            if (d == 0) {
                double& q = hspace[i][j - 1];
                q = fail_prob * q / (fail_prob * q + 1.0 - q);
            }
            if (d == 1) {
                double& q = vspace[i - 1][j];
                q = fail_prob * q / (fail_prob * q + 1.0 - q);
            }
            if (d == 2) {
                double& q = hspace[i][j];
                q = fail_prob * q / (fail_prob * q + 1.0 - q);
            }
            if (d == 3) {
                double& q = vspace[i][j];
                q = fail_prob * q / (fail_prob * q + 1.0 - q);
            }
        }
    };

    for (int turn = 0; turn <= T; turn++) {
        auto g = guess();
        cout << g << endl;      // predict
        int length;
        cin >> length;          // result
        if (length == -1) break;
        update(g, length);      // update
    }

    return 0;
}
0