結果
| 問題 |
No.2228 Creeping Ghost
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-19 18:42:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,087 bytes |
| コンパイル時間 | 2,146 ms |
| コンパイル使用メモリ | 199,496 KB |
| 最終ジャッジ日時 | 2025-02-09 17:05:13 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 TLE * 6 |
ソースコード
#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;
}