Submission #2329144


Source Code Expand

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int a, b, w, h;
vector<string> m;
int memo[16][16][16][16][4];

bool dfs(int x, int y, int aa, int bb, int d) {
  if (memo[x][y][aa][bb][d] != -1) return memo[x][y][aa][bb][d];
  if (x == w-2 && y == h-2 && aa == 0 && bb == 0)
    return memo[x][y][aa][bb][d] = true;
  bool r = false;

  {
    int nx = x + dx[d], ny = y + dy[d];
    if (m[ny][nx] == '.')
      r |= dfs(nx, ny, aa, bb, d);
  }
  if (aa > 0) {
    int nd = (d+3)%4;
    int nx = x + dx[nd], ny = y + dy[nd];
    if (m[ny][nx] == '.')
      r |= dfs(nx, ny, aa-1, bb, nd);
  }
  if (bb > 0) { // L
    int nd = (d+1)%4;
    int nx = x + dx[nd], ny = y + dy[nd];
    if (m[ny][nx] == '.')
      r |= dfs(nx, ny, aa, bb-1, nd);
  }

  return memo[x][y][aa][bb][d] = r;
}

int main() {
  cin >> a >> b >> h >> w;
  m = vector<string>(h);
  for (int i=0; i<h; i++) cin >> m[i];
  for (int i=0; i<16; i++)
    for (int j=0; j<16; j++)
      for (int u=0; u<16; u++)
        for (int v=0; v<16; v++)
          for (int k=0; k<4; k++)
            memo[i][j][u][v][k] = -1;
  cout << (dfs(1, 1, a, b, 1) ? "Yes" : "No") << endl;
  return 0;
}

Submission Info

Submission Time
Task B - 駆け抜けろ!埼大山車部!!
User suminos
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1283 Byte
Status AC
Exec Time 3 ms
Memory 1280 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 5
AC × 30
Set Name Test Cases
Sample s1.txt, s2.txt, seica1.txt, seica2.txt, seica3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, s1.txt, s2.txt, seica1.txt, seica2.txt, seica3.txt
Case Name Status Exec Time Memory
01.txt AC 2 ms 1280 KiB
02.txt AC 2 ms 1280 KiB
03.txt AC 2 ms 1280 KiB
04.txt AC 2 ms 1280 KiB
05.txt AC 2 ms 1280 KiB
06.txt AC 2 ms 1280 KiB
07.txt AC 2 ms 1280 KiB
08.txt AC 2 ms 1280 KiB
09.txt AC 2 ms 1280 KiB
10.txt AC 2 ms 1280 KiB
11.txt AC 2 ms 1280 KiB
12.txt AC 2 ms 1280 KiB
13.txt AC 2 ms 1280 KiB
14.txt AC 1 ms 1280 KiB
15.txt AC 2 ms 1280 KiB
16.txt AC 2 ms 1280 KiB
17.txt AC 1 ms 1280 KiB
18.txt AC 2 ms 1280 KiB
19.txt AC 1 ms 1280 KiB
20.txt AC 1 ms 1280 KiB
21.txt AC 1 ms 1280 KiB
22.txt AC 2 ms 1280 KiB
23.txt AC 1 ms 1280 KiB
24.txt AC 2 ms 1280 KiB
25.txt AC 2 ms 1280 KiB
s1.txt AC 2 ms 1280 KiB
s2.txt AC 2 ms 1280 KiB
seica1.txt AC 2 ms 1280 KiB
seica2.txt AC 2 ms 1280 KiB
seica3.txt AC 3 ms 1280 KiB