結果

問題 No.2928 Gridpath
ユーザー yel_ow
提出日時 2024-11-24 16:27:45
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 3,136 ms
コンパイル使用メモリ 262,448 KB
実行使用メモリ 18,048 KB
最終ジャッジ日時 2024-11-24 16:27:50
合計ジャッジ時間 4,560 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <monsterenergy>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int MAX = 1e9;
const int MIN = -1*1e9;
const ll MAXLL = 1e18;
const ll MINLL = -1*1e18;
const vector<int> dx = {0, 1, 0, -1};
const vector<int> dy = {1, 0, -1, 0};

int Ans = 0;
map<vector<vector<bool>>,bool> DP;
int H,W,S1,S2,G1,G2;
void DFS(int I, int J, vector<vector<bool>> G)
{
    if(DP[G]) return;
    DP[G] = true;
    if(I == G1 && J == G2)
    {
		Ans++;
        return;
    }
    for(int i = 0; i < 4; i++)
    {
        int ni = I+dx[i];
        int nj = J+dy[i];
        if(ni <= 0 || H < ni || nj <= 0 || W < nj) continue;
        G[I][J] = false;
        if(!G[ni][nj] && !G[ni-1][nj] && !G[ni+1][nj] && !G[ni][nj-1] && !G[ni][nj+1])
        {
        //	cout << I << " " << J << " " << ni << " " << nj << endl;
            G[I][J] = true;
            G[ni][nj] = true;
            DFS(ni,nj,G);
            G[ni][nj] = false;
        }
        G[I][J] = true;
    }
    G[I][J] = true;
    return;
}

int main()
{
    vector<vector<bool>> G(8,vector<bool>(8));
    cin >> H >> W;
    cin >> S1 >> S2 >> G1 >> G2;
    G[S1][S2] = true;
    DFS(S1,S2,G);
    cout << Ans << endl;
    return 0;
}
0