結果

問題 No.331 CodeRunnerでやれ
ユーザー naimonon77naimonon77
提出日時 2016-02-26 22:09:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,765 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 156,028 KB
実行使用メモリ 24,408 KB
平均クエリ数 25.41
最終ジャッジ日時 2023-09-23 09:00:58
合計ジャッジ時間 7,605 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます

ソースコード

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 15

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

void draw_map(char map[][SIZE],int a,int x, int y,int muki) {
  int i;
  for(i=0;i<a;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;
    }
  }
  
  // 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> route1;
  int x,y;
  int index;
};

bool map_search(char map[][SIZE],
  int x,int y,queue<route2>& q,route2 now) {
  if(map[x][y] == '.' || map[x][y] == 0) {
    route2 next = now;
    next.x = x , next.y = y;
    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;
  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().route1.push_back(l);
    }
    if( map_search(map,x+1, y ,q,now) ) {
      q.front().route1.push_back(r);
    }
    if( map_search(map, x ,y-1,q,now) ) {
      q.front().route1.push_back(down);
    }
    if( map_search(map, x ,y+1,q,now) ) {
      q.front().route1.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 route;
  print_map(map);
  while(cin >> s) {
    if(strcmp(s,"Merry") == 0)  break;
    int a = atoi(s);
    if(a > 50) cout << "F" << endl;
    else {
      draw_map(map,a,x,y,muki);
      print_map(map);
      if(route.route1.size() == route.index) {
        route = wfs(map,x,y,muki);
      }
      char c;
      if(route.route1[route.index] == muki) c = 'F';
      else {
        switch(rand() % 2) {
        case 0: c = 'R'; break;
        case 1: c = 'L'; break;
        }
        if(c == 'R') {
          muki++;
          if(muki > l) muki = up;
        }
        else {
          muki--;
          if(muki < up) muki = l;
        }
      }
      cout << c << endl;
    }
  }
  cin >> s;
  return 0;
}
0