結果
問題 | No.331 CodeRunnerでやれ |
ユーザー |
![]() |
提出日時 | 2016-02-27 15:30:28 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,799 bytes |
コンパイル時間 | 669 ms |
コンパイル使用メモリ | 72,680 KB |
実行使用メモリ | 83,360 KB |
最終ジャッジ日時 | 2024-07-16 23:02:55 |
合計ジャッジ時間 | 13,610 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 1 |
other | TLE * 1 -- * 15 |
ソースコード
#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 fieldint 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 checkif( 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 checkif( 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 movestd::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;}