結果

問題 No.331 CodeRunnerでやれ
ユーザー maimai
提出日時 2016-05-27 00:16:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,823 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 186,480 KB
実行使用メモリ 84,880 KB
最終ジャッジ日時 2023-09-23 23:57:17
合計ジャッジ時間 15,111 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long int ll;

vector<vector<int>> swapper;

int turnTableLX[3][3]={{0,-1,0},{0,0,0},{0,1,0}};
int turnTableLY[3][3]={{0,0,0},{1,0,-1},{0,0,0}};

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

inline void turnLeft(){
    int x=vx,y=vy;
    vx=turnTableLX[x][y];
    vy=turnTableLY[x][y];
}
inline void turnRight(){
    int x=vx,y=vy;
    vx=-turnTableLX[x][y];
    vy=-turnTableLY[x][y];
}

inline bool isKnown(int x,int y){
    return field.count(make_pair(x+1,y)) 
        && field.count(make_pair(x-1,y)) 
        && field.count(make_pair(x,y+1)) 
        && field.count(make_pair(x,y+1)) ;
}

void finalAction(){
    int l;
    while(scanf("%d",&l)>0){
        puts("F\n");
    }
    exit(0);
}

void check(){
    int l,i;
    if (scanf("%d",&l)<=0) exit(0);
    if (l==20151224) finalAction();
    for (i=0;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;
            q.push(vector<int>{px-1,py,-1,0});
            q.push(vector<int>{px+1,py,1,0});
            q.push(vector<int>{px,py-1,0,-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]))) q.push(vector<int>{v[0]+1,v[1],v[2],v[3]});
                    if (!dp.count(make_pair(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))) q.push(vector<int>{v[0],v[1]+1,v[2],v[3]});
                    if (!dp.count(make_pair(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){
                        puts("F\n");
                    }else{
                        if (turnTableLX[vx][vy]==v[2] && turnTableLX[vx][vy]==v[3]){
                            puts("L\n");
                            turnLeft();
                        }else{
                            puts("R\n");
                            turnRight();
                        }
                    }
                    break;
                }
                q.pop();
            }
        }else{
            puts("L\n");
            turnLeft();
        }
    }
}

int main(){
    int i,j,k,l,m,n,h,x,y;
    
    while (true){
        check();
        action();
    }
    
    return 0;
}
0