結果

問題 No.331 CodeRunnerでやれ
ユーザー Tsuneo Yoshioka
提出日時 2015-12-24 00:50:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 308 ms / 5,000 ms
コード長 1,824 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 66,616 KB
実行使用メモリ 25,232 KB
平均クエリ数 346.24
最終ジャッジ日時 2024-07-16 22:26:25
合計ジャッジ時間 6,428 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;
int main(void){
    // Here your code !
    ios::sync_with_stdio(false);
    string str;
    vector< vector<bool> >visited(100, vector<bool>(100, false));
    int cur_x = 50, cur_y = 50;
    int cur_d = 0;
    int dx[] = {1,0,-1,0};
    int dy[] = {0,1,0,-1};
    vector <int> st;
    
    while(!cin.eof()){
        getline(cin, str);
        //cout << "str=" << str << "..." << endl;
        //cout << "cur_x=" << cur_x << ", cur_y=" << cur_y << ", cur_d=" << cur_d << endl;
        //cout << "stack: ";
        //for(auto d:st){
        //    cout << d << " ";
        //}
        //cout << endl;
        
        if(str=="Merry Christmas!"){
            exit(0);
        }
        int i = atoi(str.c_str());
        
        visited[cur_x][cur_y] = true;
        if(i==0){
            visited[cur_x + dx[cur_d]][cur_y + dy[cur_d]] = true;
        }
        int next_d = -1;
        for(int d=0;d<4;d++){
            if(! visited[cur_x + dx[d]][cur_y + dy[d]]){
                next_d = d;
                break;
            }
        }
        if(next_d==-1){
            int d = (st.back() + 2)%4;
            if(cur_d==d){
                cur_x += dx[cur_d];
                cur_y += dy[cur_d];
                st.pop_back();
                cout << "F" << endl << flush;
            }else{
                cur_d=(cur_d+1)%4;
                cout << "L" << endl << flush;
            }
        }else{
            if(cur_d==next_d){
                cur_x += dx[cur_d];
                cur_y += dy[cur_d];
                st.push_back(cur_d);
                cout << "F" << endl << flush;
            }else{
                cur_d=(cur_d+1)%4;
                cout << "L" << endl << flush;
            }
        }
    }
}
0