結果
| 問題 |
No.2228 Creeping Ghost
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-24 23:21:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,688 bytes |
| コンパイル時間 | 4,659 ms |
| コンパイル使用メモリ | 262,292 KB |
| 最終ジャッジ日時 | 2025-02-10 22:45:24 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 WA * 6 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;
using TUP = tuple<P,P>;
map<TUP,int> state_idx;
int N;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
string ds = "DRUL";
string buff;
int roopst = -1;
void dfs(TUP cur,int turn){
if(state_idx.count(cur)&&turn%4==0){
auto [nxp,nxg] = cur;
//cout<<nxp.first<<' '<<nxp.second<<' '<<nxg.first<<' '<<nxg.second<<endl;
roopst = state_idx[cur];
return;
}
state_idx[cur] = turn-1;
for(int i= 0;i<4;i++){
auto [nxp,nxg] = cur;
nxp.first += dx[i];
nxp.second += dy[i];
if(nxp.first<0||nxp.first>=5)continue;
if(nxp.second<0||nxp.second>=5)continue;
if(turn%4==3){
auto tmp = get<0>(cur);
for(int i = 0;i<3;i++){
auto move = buff[buff.size()-1-i];
if(move=='U')tmp.first++;
if(move=='D')tmp.first--;
if(move=='L')tmp.second++;
if(move=='R')tmp.second--;
}
nxg = tmp;
}
if(nxp.first==nxg.first||nxp.second==nxg.second){
continue;
}
TUP nx(nxp,nxg);
buff.push_back(ds[i]);
dfs(nx,turn+1);
if(roopst!=-1)break;
buff.pop_back();;
}
state_idx.erase(cur);
}
void solve(){
auto cur = TUP(P(0,0),P(-1,-1));
dfs(cur,0);
ll loopsize = buff.size()-roopst;
string loop = buff.substr(roopst,loopsize);
while(buff.size()<N){
buff+=loop;
}
int x=0,y=0;
/*
for(int i = 0;i<N;i++){
if(buff[i]=='U')x--;
if(buff[i]=='D')x++;
if(buff[i]=='R')y++;
if(buff[i]=='L')y--;
}
*/
//cout<<buff.substr(0,roopst)<<endl;
//cout<<loop<<endl;
//cout<<x<<' '<<y<<endl;
cout<<buff.substr(0,N)<<endl;
}
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> N;
solve();
}