結果

問題 No.5006 Hidden Maze
ユーザー HaaHaa
提出日時 2022-06-12 16:10:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,995 bytes
コンパイル時間 1,889 ms
実行使用メモリ 22,864 KB
スコア 81,182
平均クエリ数 189.18
最終ジャッジ日時 2022-06-12 16:16:52
合計ジャッジ時間 9,796 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
21,756 KB
testcase_01 AC 108 ms
21,928 KB
testcase_02 AC 39 ms
22,744 KB
testcase_03 AC 26 ms
22,396 KB
testcase_04 AC 28 ms
21,940 KB
testcase_05 AC 27 ms
21,756 KB
testcase_06 AC 37 ms
21,736 KB
testcase_07 AC 23 ms
21,760 KB
testcase_08 AC 36 ms
21,768 KB
testcase_09 AC 24 ms
22,856 KB
testcase_10 AC 43 ms
21,916 KB
testcase_11 AC 28 ms
22,228 KB
testcase_12 AC 29 ms
22,192 KB
testcase_13 AC 25 ms
21,968 KB
testcase_14 AC 44 ms
21,892 KB
testcase_15 AC 20 ms
22,228 KB
testcase_16 AC 23 ms
21,892 KB
testcase_17 AC 21 ms
22,192 KB
testcase_18 AC 33 ms
22,600 KB
testcase_19 AC 24 ms
22,608 KB
testcase_20 AC 22 ms
22,396 KB
testcase_21 AC 30 ms
21,980 KB
testcase_22 AC 24 ms
21,940 KB
testcase_23 AC 35 ms
21,928 KB
testcase_24 AC 31 ms
21,968 KB
testcase_25 AC 23 ms
22,432 KB
testcase_26 AC 106 ms
22,456 KB
testcase_27 AC 41 ms
22,864 KB
testcase_28 AC 21 ms
22,228 KB
testcase_29 AC 35 ms
22,252 KB
testcase_30 AC 21 ms
21,768 KB
testcase_31 AC 33 ms
21,916 KB
testcase_32 AC 42 ms
22,204 KB
testcase_33 AC 34 ms
22,588 KB
testcase_34 AC 35 ms
22,228 KB
testcase_35 AC 41 ms
22,264 KB
testcase_36 AC 22 ms
21,868 KB
testcase_37 AC 57 ms
22,384 KB
testcase_38 AC 107 ms
22,636 KB
testcase_39 AC 44 ms
21,844 KB
testcase_40 AC 26 ms
21,768 KB
testcase_41 AC 29 ms
22,576 KB
testcase_42 AC 22 ms
21,980 KB
testcase_43 AC 26 ms
21,892 KB
testcase_44 AC 20 ms
21,940 KB
testcase_45 AC 106 ms
22,240 KB
testcase_46 AC 96 ms
21,940 KB
testcase_47 AC 25 ms
22,588 KB
testcase_48 AC 33 ms
21,796 KB
testcase_49 AC 112 ms
22,564 KB
testcase_50 AC 23 ms
22,392 KB
testcase_51 AC 20 ms
22,384 KB
testcase_52 AC 33 ms
21,880 KB
testcase_53 AC 32 ms
22,600 KB
testcase_54 AC 21 ms
21,928 KB
testcase_55 AC 27 ms
22,216 KB
testcase_56 AC 23 ms
21,980 KB
testcase_57 AC 27 ms
21,940 KB
testcase_58 AC 27 ms
21,992 KB
testcase_59 AC 26 ms
21,868 KB
testcase_60 AC 21 ms
21,980 KB
testcase_61 AC 32 ms
21,868 KB
testcase_62 AC 33 ms
21,928 KB
testcase_63 AC 27 ms
21,768 KB
testcase_64 AC 32 ms
21,940 KB
testcase_65 AC 21 ms
21,892 KB
testcase_66 AC 96 ms
22,612 KB
testcase_67 AC 65 ms
22,240 KB
testcase_68 AC 20 ms
21,928 KB
testcase_69 AC 23 ms
22,552 KB
testcase_70 AC 22 ms
22,612 KB
testcase_71 AC 27 ms
22,252 KB
testcase_72 AC 29 ms
22,608 KB
testcase_73 AC 72 ms
22,392 KB
testcase_74 AC 28 ms
21,940 KB
testcase_75 AC 29 ms
22,192 KB
testcase_76 AC 21 ms
21,880 KB
testcase_77 AC 42 ms
22,612 KB
testcase_78 AC 27 ms
22,692 KB
testcase_79 AC 48 ms
21,928 KB
testcase_80 AC 21 ms
22,264 KB
testcase_81 AC 24 ms
22,612 KB
testcase_82 AC 19 ms
21,928 KB
testcase_83 AC 20 ms
22,576 KB
testcase_84 AC 24 ms
22,204 KB
testcase_85 AC 21 ms
21,792 KB
testcase_86 AC 19 ms
21,880 KB
testcase_87 AC 29 ms
22,048 KB
testcase_88 AC 27 ms
21,868 KB
testcase_89 AC 114 ms
22,576 KB
testcase_90 AC 49 ms
21,880 KB
testcase_91 AC 29 ms
21,748 KB
testcase_92 AC 31 ms
21,724 KB
testcase_93 AC 22 ms
21,940 KB
testcase_94 AC 35 ms
22,588 KB
testcase_95 AC 38 ms
21,736 KB
testcase_96 AC 19 ms
21,880 KB
testcase_97 AC 48 ms
22,396 KB
testcase_98 AC 114 ms
21,952 KB
testcase_99 AC 23 ms
22,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

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)]<rand()%10){
                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)]<rand()%10){
                pre[id(tx,ty)]=perm[i];
                sque.push({tx,ty});
            }
        }
    }
    int px=H-1, py=W-1;
    if(pre[id(px,py)]==-1)
        return newroute();
    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=newroute();
        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;
}
0