結果
| 問題 |
No.5006 Hidden Maze
|
| ユーザー |
Haa
|
| 提出日時 | 2022-06-12 16:42:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 151 ms / 2,000 ms |
| コード長 | 3,390 bytes |
| コンパイル時間 | 1,759 ms |
| 実行使用メモリ | 22,864 KB |
| スコア | 82,298 |
| 平均クエリ数 | 178.02 |
| 最終ジャッジ日時 | 2022-06-12 16:43:04 |
| 合計ジャッジ時間 | 10,287 ms |
|
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 100 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
const string dir="RDLU";
map<char,int> rid={{'R',0},{'D',1},{'L',2},{'U',3}};
int H, W, P;
VI rea(20*20,0);
VVI wall(20*20,VI(20*20,1));
inline int id(int x, int y){
return x*W+y;
}
double Uniform(){
return ((double)rand()+1.0)/((double)RAND_MAX+2.0);
}
double nom(double mu, double sigma){
double z=sqrt(-2.0*log(Uniform()))*sin(2.0*M_PI*Uniform());
return mu+sigma*z;
}
string newroute(){
VI pre(H*W,-1); pre[id(0,0)]=-2;
queue<pair<int,int>> que, sque; que.push({0,0});
vector<pair<int,int>> ps;
while(!que.empty()){
int x=que.front().first;
int y=que.front().second;
que.pop();
VI perm={0,1,2,3};
random_shuffle(ALL(perm));
REP(i,4){
int tx=x+dx[perm[i]];
int ty=y+dy[perm[i]];
if(tx<0||tx>=H||ty<0||ty>=W)
continue;
if(pre[id(tx,ty)]!=-1)
continue;
if(rea[id(tx,ty)]){
if(!wall[id(x,y)][id(tx,ty)]){
pre[id(tx,ty)]=perm[i];
que.push({tx,ty});
}
}
else if(wall[id(x,y)][id(tx,ty)]<abs(nom(0,0.5))*P){
pre[id(tx,ty)]=perm[i];
ps.push_back({tx,ty});
}
}
}
random_shuffle(ALL(ps));
for(auto p:ps) sque.push(p);
while(!sque.empty()){
int x=sque.front().first;
int y=sque.front().second;
sque.pop();
VI perm={0,1,2,3};
random_shuffle(ALL(perm));
REP(i,4){
int tx=x+dx[perm[i]];
int ty=y+dy[perm[i]];
if(tx<0||tx>=H||ty<0||ty>=W)
continue;
if(pre[id(tx,ty)]!=-1)
continue;
if(!rea[id(tx,ty)]&&wall[id(x,y)][id(tx,ty)]<abs(nom(0,0.5))*P){
pre[id(tx,ty)]=perm[i];
sque.push({tx,ty});
}
}
}
int px=H-1, py=W-1;
if(pre[id(px,py)]==-1)
return "";
string ret="";
while(px!=0||py!=0){
int p=pre[id(px,py)];
ret+=dir[p];
px-=dx[p];
py-=dy[p];
}
reverse(ALL(ret));
return ret;
}
void solve(){
rea[id(0,0)]=1;
cin >> H >> W >> P;
int X;
REP(i,1001){
string s;
REP(j,10){
s=newroute();
if(s.size()!=0)
break;
}
if(s.size()==0){
REP(j,W-1) s+='R';
REP(j,H-1) s+='D';
}
cout << s << endl;
cin >> X;
if(X==-1)
break;
int px=0, py=0;
REP(j,X+1){
int npx=px+dx[rid[s[j]]];
int npy=py+dy[rid[s[j]]];
if(j<X){
wall[id(px,py)][id(npx,npy)]=0;
rea[id(npx,npy)]=1;
}
else if(wall[id(px,py)][id(npx,npy)]!=0){
wall[id(px,py)][id(npx,npy)]++;
}
px=npx;
py=npy;
}
}
}
int main(){
solve();
return 0;
}
Haa