結果

問題 No.331 CodeRunnerでやれ
ユーザー naimonon77naimonon77
提出日時 2016-02-27 04:44:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,066 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 155,208 KB
実行使用メモリ 91,692 KB
平均クエリ数 1.12
最終ジャッジ日時 2023-09-23 23:15:35
合計ジャッジ時間 8,889 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
24,420 KB
testcase_01 AC 140 ms
23,652 KB
testcase_02 TLE -
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 #

#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 50

enum Muki{
  up,r,down,l
};


void draw_map(char map[][SIZE],int a,int x, int y,int muki) {
  int i;
  map[x][y] = '.';
  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] = 'v';
}

void print_map(char map[][SIZE]) {
  int i,j;
  for(i=0;i<SIZE;i++) {
    for(j=0;j<SIZE;j++) {
      if(map[j][i] == 0) printf(" ");
      else printf("%c",map[j][i]);
    }
    puts("");
  }
}

class Route2{
public:
  vector<int> route;
  bool visited[SIZE][SIZE];
  int x,y;
  int index;
  Route2() {
    int i,j;
    rep(i,SIZE) {
      rep(j,SIZE) visited[i][j] = false;
    }
  }
};

bool map_search(char map[][SIZE],
  int x,int y,queue<Route2>& q,Route2& now) {
    if( (not now.visited[x][y]) && map[x][y] != '#' ) {
    Route2 next = now;
    next.x = x , next.y = y;
    next.visited[x][y] = true;
    q.push(next);
    return true;
  }
  return false;
}

Route2 wfs(char map[][SIZE],int x,int y,int muki) {
  queue< Route2 > q;
  Route2 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();
    Route2 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);
    }
  }
}

int main() {
  /*
  cin.tie(0);
  ios::sync_with_stdio(false);
  */
  char map[SIZE][SIZE] = {0};  
  int x = SIZE/2 ,y = SIZE/2;
  int muki = down;
  int i,j,k;
  char s[20];
  Route2 route2;
  route2.index = 0;
  while(cin >> s) {
    if(strcmp(s,"Merry") == 0)  break;
    int a = atoi(s);
    if(a > 50) std::cout << "F" << endl;
    else {
      draw_map(map,a,x,y,muki);
      // print_map(map);
      int& index = route2.index;
      if(a == 0 or route2.route.size() == index) {
        route2 = wfs(map,x,y,muki);
      }
      char c;
      if(a != 0 && route2.route[index] == muki) {
        c = 'F';
        index++;
      }
      else {
        c = 'L';
        muki--;
        if(muki < up) muki = l;
      }
      cout << c << endl;
    }
  }
  cin >> s;
  return 0;
}
0