結果

問題 No.2228 Creeping Ghost
ユーザー hari64hari64
提出日時 2022-12-19 18:42:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,087 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 207,160 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-29 02:21:41
合計ジャッジ時間 5,851 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,624 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef hari64
#include <bits/stdc++.h>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#define debug(...)
#else
#include "viewer.hpp"
#define debug(...) viewer::_debug(__LINE__, #__VA_ARGS__, __VA_ARGS__)
#endif  // clang-format off
using namespace std;constexpr int INF=1001001001;constexpr long long
INFll=1001001001001001001; template<class T>bool chmax(T&a,const T&b){return
a<b?a=b,1:0;} template<class T>bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
// clang-format on

constexpr int DY[4] = {-1, 1, 0, 0};
constexpr int DX[4] = {0, 0, -1, 1};
constexpr char UDLR[4] = {'U', 'D', 'L', 'R'};

vector<pair<int, int>> XYs = {{0, 0}};
vector<int> hist;
string ans;

int T;

void dfs(int t, int x, int y) {
    if (!ans.empty()) return;
    if (t == T + 100) {
        ans = "";
        for (auto& i : hist) ans += UDLR[i];
        return;
    }
    int ghostT = 4 * (t / 4 - 1);
    int ghostX = ghostT < 0 ? -1 : XYs[ghostT].first;
    int ghostY = ghostT < 0 ? -1 : XYs[ghostT].second;
    if (x == ghostX || y == ghostY) return;
    for (int k = 0; k < 4; k++) {
        int nx = x + DX[k];
        int ny = y + DY[k];
        if (!(0 <= nx && nx < 5 && 0 <= ny && ny < 5)) continue;
        if (nx == ghostX || ny == ghostY) continue;
        hist.push_back(k);
        XYs.emplace_back(nx, ny);
        dfs(t + 1, nx, ny);
        hist.pop_back();
        XYs.pop_back();
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    // T = 1000;
    // dfs(0, 0, 0);
    // cout << ans << endl;

    /** Result:
     * DU
     * DRDUDRDDRRUDULUUDLUULLDU
     * DRDUDRDDRRUDULUUDLUULLDU
     * DRDUDRDDRRUDULUUDLUULLDU
     * DRDUDRDDRRUDULUUDLUULLDU
     * ...
     */

    cin >> T;
    assert(1 <= T && T <= 1000000);

    dfs(0, 0, 0);
    cout << string(ans.begin(), ans.begin() + T) << endl;

    // string strAns = "DU";

    // while (int(strAns.size()) < T) {
    //     strAns += "DRDUDRDDRRUDULUUDLUULLDU";
    // }

    // cout << string(strAns.begin(), strAns.begin() + T) << endl;

    return 0;
}
0