結果

問題 No.331 CodeRunnerでやれ
ユーザー maimai
提出日時 2016-05-27 12:45:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 336 ms / 5,000 ms
コード長 3,984 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 192,592 KB
実行使用メモリ 24,384 KB
平均クエリ数 356.12
最終ジャッジ日時 2023-09-23 23:58:12
合計ジャッジ時間 7,850 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
23,832 KB
testcase_01 AC 136 ms
24,384 KB
testcase_02 AC 169 ms
23,980 KB
testcase_03 AC 193 ms
23,608 KB
testcase_04 AC 173 ms
23,820 KB
testcase_05 AC 172 ms
24,048 KB
testcase_06 AC 196 ms
23,652 KB
testcase_07 AC 248 ms
23,644 KB
testcase_08 AC 229 ms
23,368 KB
testcase_09 AC 300 ms
23,884 KB
testcase_10 AC 223 ms
23,536 KB
testcase_11 AC 248 ms
24,252 KB
testcase_12 AC 289 ms
23,400 KB
testcase_13 AC 230 ms
24,000 KB
testcase_14 AC 285 ms
24,312 KB
testcase_15 AC 293 ms
24,040 KB
testcase_16 AC 336 ms
23,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;

vector<vector<int>> swapper;

int turnTableRX[3][3]={{0,0,0},{1,0,-1},{0,0,0}};
int turnTableRY[3][3]={{0,-1,0},{0,0,0},{0,1,0}};

int vx=0,vy=1;
int px=0,py=0;
bool target=false;
int tx,ty;
map<pair<int,int>,int> field;

void print(){
    int x,y;
    for (y=-1;y<5;y++){
        for (x=-3;x<3;x++){
            pair<int,int> p=make_pair(x,y);
            if (px==x&&py==y) cout<<"[";else cout<<" ";
            if (field.count(p)){
                cout << field[p];
            }else{
                cout << "?";
            }

            if (px==x&&py==y) cout<<"]";else cout<<" ";
        }
        cout<<endl;
    }
}

inline bool moveable(int x,int y){
    pair<int,int> p=make_pair(x,y);
    return field.count(p) && field[p];
}

inline void turnLeft(){
    int x=vx,y=vy;
    vx=-turnTableRX[x+1][y+1];
    vy=-turnTableRY[x+1][y+1];
}
inline void turnRight(){
    int x=vx,y=vy;
    vx=turnTableRX[x+1][y+1];
    vy=turnTableRY[x+1][y+1];
}

inline bool isKnown(int x,int y){
    int dx=0,dy=1;
    pair<int,int> p;
    for (int i=0;i<4;i++){
        for (int j=1;j<60;j++){
            p.first=x+dx*j;
            p.second=y+dy*j;
            if (!field.count(p)){
                return false;
            }else if(!field[p]) break;
        }
        int t=dx;
        dx=turnTableRX[dx+1][dy+1];
        dy=turnTableRY[t+1][dy+1];
    }
    return true ;
}

void finalAction(){
    int l;string buff;
    do{
        cout<<"F"<<endl;
        cin >> buff;
    }while(buff[0]!='M');
    exit(0);
}

void check(){
    int l,i;
    if (scanf("%d",&l)<=0) exit(0);
    if (l==20151224) finalAction();
    for (i=1;i<=l;i++){
        field[make_pair(px+vx*i,py+vy*i)]=1;
    }
    field[make_pair(px+vx*i,py+vy*i)]=0;
}

void action(){
    int b;
    if (target){
        // 使ってない
    }else{
        if (isKnown(px,py)){
            map<pair<int,int>,bool> dp;
            queue<vector<int>> q;
            if (moveable(px-1,py)) q.push(vector<int>{px-1,py,-1,0});
            if (moveable(px+1,py)) q.push(vector<int>{px+1,py,1,0});
            if (moveable(px,py-1)) q.push(vector<int>{px,py-1,0,-1});
            if (moveable(px,py+1)) q.push(vector<int>{px,py+1,0,1});
            while (!q.empty()){
                vector<int> &v=q.front();
                dp[make_pair(v[0],v[1])]=true;
                if (isKnown(v[0],v[1])){
                    if (!dp.count(make_pair(v[0]+1,v[1]))
                        && moveable(v[0]+1,v[1])) q.push(vector<int>{v[0]+1,v[1],v[2],v[3]});
                    if (!dp.count(make_pair(v[0]-1,v[1]))
                        && moveable(v[0]-1,v[1])) q.push(vector<int>{v[0]-1,v[1],v[2],v[3]});
                    if (!dp.count(make_pair(v[0],v[1]+1))
                        && moveable(v[0],v[1]+1)) q.push(vector<int>{v[0],v[1]+1,v[2],v[3]});
                    if (!dp.count(make_pair(v[0],v[1]-1))
                        && moveable(v[0],v[1]-1)) q.push(vector<int>{v[0],v[1]-1,v[2],v[3]});
                }else{
                    // target=true;
                    // tx=v[0];ty=v[1];
                    // action();
                    if (v[2]==vx && v[3]==vy){
                        cout<<"F"<<endl;
                        px+=vx;py+=vy;
                    }else{
                        if (turnTableRX[vx+1][vy+1]==v[2] && turnTableRX[vx+1][vy+1]==v[3]){
                            cout<<"R"<<endl;
                            turnRight();
                        }else{
                            cout<<"L"<<endl;
                            turnLeft();
                        }
                    }
                    break;
                }
                q.pop();
            }
        }else{
            cout<<"R"<<endl;
            turnRight();
        }
    }
}

int main(){
    
    field[make_pair(0,0)]=1;
    
    while (true){
        check();
        action();
        //print();
    }
    
    return 0;
}
0