結果

問題 No.331 CodeRunnerでやれ
ユーザー alpha_virginisalpha_virginis
提出日時 2016-02-27 15:30:28
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,799 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 73,196 KB
実行使用メモリ 83,904 KB
最終ジャッジ日時 2023-09-23 23:16:49
合計ジャッジ時間 13,400 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>

enum {
  unknown,
  space,
  wall,
};

int field[64][64];
int x = 32, y = 32;
int d = 0;

void printfield() {
  for(int i = 0; i < 64; ++i) {
    for(int j = 0; j < 64; ++j) {
      if( y == i and x == j ) {
        char t[5] = "RDLU";
        printf("%c", t[d]);
        continue;
      }
      char t2[4] = "+ #";
      printf("%c", t2[field[i][j]]);
    }
    printf("\n");
  }
}

int main() {
  field[y][x] = space;

  std::string str;
  for(;;) {
    //printfield();
    std::getline(std::cin, str);
    if( str == "Merry Christmas!" ) break;
    int in = std::stoi(str);

    // step 1 : end?
    if( in == 20151224 ) {
      std::cout << "F" << std::endl;
      for(;;) {
        std::cin >> str;
        if( str == "Merry Christmas!" ) {
          break;
        }
      }
      break;
    }

    // step 2 : update field
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    int nx = x + dx[d], ny = y + dy[d];
    for(int i = 0; i < in; ++i) {
      field[ny][nx] = space;
      nx += dx[d];
      ny += dy[d];
    }
    field[ny][nx] = wall;

    // step 3 : right check
    if( field[y+dy[(d+1)%4]][x+dx[(d+1)%4]] == unknown ) {
      std::cout << "R" << std::endl;
      d = (d + 1) % 4;
      continue;
    }

    // step 4 : left check
    if( field[y+dy[(d+3)%4]][x+dx[(d+3)%4]] == unknown ) {
      std::cout << "L" << std::endl;
      d = (d + 3) % 4;
      continue;
    }

    if( field[y+dy[(d+2)%4]][x+dx[(d+2)%4]] == unknown ) {
      std::cout << "L" << std::endl;
      d = (d + 3) % 4;
      std::cin >> str;
      std::cout << "L" << std::endl;
      d = (d + 3) % 4;
      continue;
    }
    
    // step 5 move
    std::vector<int> movable = {};
    for(int i = 0; i < 4; ++i) {
      if( field[y+dy[(d+i)%4]][x+dx[(d+i)%4]] == space ) {
        movable.push_back(i);
      }
    }
    int choice = movable[rand()%movable.size()];
    switch( choice ) {
    case 0 :
      std::cout << "F" << std::endl;
      x += dx[d]; y += dy[d];
      break;
    case 1 :
      std::cout << "R" << std::endl;
      d = (d + 1) % 4;
      std::cin >> str;      
      std::cout << "F" << std::endl;
      x += dx[d]; y += dy[d];
      break;
    case 2 :
      std::cout << "R" << std::endl;
      d = (d + 1) % 4;
      std::cin >> str;      
      std::cout << "R" << std::endl;
      d = (d + 1) % 4;
      std::cin >> str;      
      std::cout << "F" << std::endl;
      x += dx[d]; y += dy[d];
      break;
    case 3 :
      std::cout << "L" << std::endl;
      d = (d + 3) % 4;
      std::cin >> str;      
      std::cout << "F" << std::endl;
      x += dx[d]; y += dy[d];
      break;
    }
  }
    
  return 0;
}
0