結果
| 問題 | No.331 CodeRunnerでやれ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-27 05:30:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,509 bytes |
| 記録 | |
| コンパイル時間 | 1,585 ms |
| コンパイル使用メモリ | 170,684 KB |
| 実行使用メモリ | 96,156 KB |
| 平均クエリ数 | 0.88 |
| 最終ジャッジ日時 | 2024-07-16 23:01:45 |
| 合計ジャッジ時間 | 9,022 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 TLE * 1 -- * 14 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include "bits\stdc++.h"
#endif
#include <vector>
#include <set>
#include <string>
#include <queue>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define SIZE 10
enum Muki{
up,r,down,l
};
void draw_map(char map[][SIZE],int a,int x, int y,int muki) {
int i;
for(i=1;i<a+1;i++) {
switch(muki) {
case up : map[ x ][y+i] = '.'; break;
case down : map[ x ][y-i] = '.'; break;
case r : map[x+i][ y ] = '.'; break;
case l : map[x-i][ y ] = '.'; break;
}
}
switch(muki) {
case up : map[ x ][y+i] = '#'; break;
case down : map[ x ][y-i] = '#'; break;
case r : map[x+i][ y ] = '#'; break;
case l : map[x-i][ y ] = '#'; break;
}
// map[x][y] = '!';
}
void print_map(char map[][SIZE]) {
int i,j;
for(i=SIZE-1;i>-1;i--) {
for(j=0;j<SIZE;j++) {
if(map[j][i] == 0) printf(" ");
else printf("%c",map[j][i]);
}
puts("");
}
}
class Route1{
public:
vector<int> route;
bool visited[SIZE][SIZE];
int x,y;
int index;
Route1() {
int i,j;
rep(i,SIZE) {
rep(j,SIZE) visited[i][j] = false;
}
}
};
bool map_search(char map[][SIZE],
int x,int y,queue<Route1>& q,Route1& now) {
if( (not now.visited[x][y]) && map[x][y] != '#' ) {
Route1 next = now;
next.x = x , next.y = y;
next.visited[x][y] = true;
q.push(next);
return true;
}
return false;
}
// 最も近い分からない場所を探索
// 最後は行けるか分からない
Route1 wfs(char map[][SIZE],int x,int y,int muki) {
queue< Route1 > q;
Route1 now;
now.x = x; now.y = y;
now.index = 0;
now.visited[x][y] = true;
q.push(now);
while( q.size() ) {
now = q.front(); q.pop();
Route1 next;
int x = now.x , y = now.y;
if(map[x][y] == 0) {
return now;
}
if( map_search(map,x-1, y ,q,now) ) {
q.front().route.push_back(l);
}
if( map_search(map,x+1, y ,q,now) ) {
q.front().route.push_back(r);
}
if( map_search(map, x ,y-1,q,now) ) {
q.front().route.push_back(down);
}
if( map_search(map, x ,y+1,q,now) ) {
q.front().route.push_back(up);
}
}
}
void player_move(int muki,int& x,int& y) {
switch(muki) {
case up : y++; break;
case down: y--; break;
case r : x++; break;
case l : x--; break;
}
}
int main() {
bool test = false;
/*
cin.tie(0);
ios::sync_with_stdio(false);
*/
char map[SIZE][SIZE] = {0}; // 0 or '.' or '#'
int x = SIZE/2 ,y = SIZE/2;
int muki = down;
int i,j,k;
char s[20];
Route1 route1;
route1.index = 0;
if(test) print_map(map);
map[x][y] = '!';
while(cin >> s) {
char c;
if(strcmp(s,"Merry") == 0) break;
int a = atoi(s);
if(a > 50) {
c = 'F';
player_move(muki,x,y);
}
else {
draw_map(map,a,x,y,muki);
int& index = route1.index;
if(a == 0 or route1.route.size() == index) {
route1 = wfs(map,x,y,muki);
}
if(a != 0 && route1.route[index] == muki) {
map[x][y] = '.';
player_move(muki,x,y);
map[x][y] = '!';
c = 'F';
index++;
}
else {
c = 'L';
muki--;
if(muki < up) muki = l;
}
}
if(test) print_map(map);
cout << c << endl;
}
cin >> s;
return 0;
}