Submission #2312856
Source Code Expand
Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
using State = tuple<int, int, int, int, int>;
enum { UP = 0, RIGHT, DOWN, LEFT };
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
int A, B, H, W;
string C[15];
//---------------------------------------------------------------------------------------------------
int vis[15][15][16][16][4]; // vis[y][x][a][b][dir]
#define yes "Yes"
#define no "No"
string solve() {
stack<State> st;
vis[1][1][0][0][2] = 1;
st.push(State(1, 1, 0, 0, 2));
while (!st.empty()) {
int x, y, a, b, dir;
tie(y, x, a, b, dir) = st.top();
st.pop();
if (x == W - 2 and y == H - 2 and a == A and b == B) return yes;
// 行動1
if (a < A) {
int dir2 = (dir + 3) % 4;
int xx = x + dx[dir2];
int yy = y + dy[dir2];
if (C[yy][xx] != '#' and !vis[yy][xx][a + 1][b][dir2]) {
vis[yy][xx][a + 1][b][dir2] = 1;
st.push(State(yy, xx, a + 1, b, dir2));
}
}
// 行動2
if (b < B) {
int dir2 = (dir + 1) % 4;
int xx = x + dx[dir2];
int yy = y + dy[dir2];
if (C[yy][xx] != '#' and !vis[yy][xx][a][b + 1][dir2]) {
vis[yy][xx][a][b + 1][dir2] = 1;
st.push(State(yy, xx, a, b + 1, dir2));
}
}
// 行動3
int xx = x + dx[dir];
int yy = y + dy[dir];
if (C[yy][xx] != '#' and !vis[yy][xx][a][b][dir]) {
vis[yy][xx][a][b][dir] = 1;
st.push(State(yy, xx, a, b, dir));
}
}
return no;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> A >> B >> H >> W;
rep(y, 0, H) cin >> C[y];
cout << solve() << endl;
}
Submission Info
Submission Time |
|
Task |
B - 駆け抜けろ!埼大山車部!! |
User |
hamayanhamayan |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
3113 Byte |
Status |
AC |
Exec Time |
2 ms |
Memory |
1024 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
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 |
1 ms |
384 KB |
02.txt |
AC |
2 ms |
640 KB |
03.txt |
AC |
1 ms |
512 KB |
04.txt |
AC |
1 ms |
512 KB |
05.txt |
AC |
1 ms |
512 KB |
06.txt |
AC |
1 ms |
640 KB |
07.txt |
AC |
1 ms |
384 KB |
08.txt |
AC |
1 ms |
256 KB |
09.txt |
AC |
1 ms |
256 KB |
10.txt |
AC |
1 ms |
512 KB |
11.txt |
AC |
1 ms |
384 KB |
12.txt |
AC |
1 ms |
640 KB |
13.txt |
AC |
1 ms |
512 KB |
14.txt |
AC |
1 ms |
256 KB |
15.txt |
AC |
1 ms |
384 KB |
16.txt |
AC |
1 ms |
384 KB |
17.txt |
AC |
1 ms |
256 KB |
18.txt |
AC |
1 ms |
256 KB |
19.txt |
AC |
1 ms |
256 KB |
20.txt |
AC |
1 ms |
384 KB |
21.txt |
AC |
1 ms |
256 KB |
22.txt |
AC |
1 ms |
384 KB |
23.txt |
AC |
1 ms |
384 KB |
24.txt |
AC |
1 ms |
384 KB |
25.txt |
AC |
1 ms |
256 KB |
s1.txt |
AC |
1 ms |
384 KB |
s2.txt |
AC |
1 ms |
256 KB |
seica1.txt |
AC |
2 ms |
1024 KB |
seica2.txt |
AC |
2 ms |
1024 KB |
seica3.txt |
AC |
1 ms |
768 KB |