結果

問題 No.2228 Creeping Ghost
ユーザー hari64hari64
提出日時 2022-12-19 18:41:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 2,042 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 204,764 KB
実行使用メモリ 5,128 KB
最終ジャッジ日時 2023-08-11 09:51:54
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

    // 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