結果

問題 No.331 CodeRunnerでやれ
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2015-12-24 00:49:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,810 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 67,792 KB
実行使用メモリ 24,432 KB
平均クエリ数 8.00
最終ジャッジ日時 2023-09-23 08:26:44
合計ジャッジ時間 5,046 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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