提出 #2946983


ソースコード 拡げる

#include <iostream>
#include <string>
#include <vector>

using namespace std;

template <typename T>
using V = vector<T>;
using ll = long long;

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

/* ---------- ここまでマクロ ---------- */

const ll dx[4] = {0, -1, 0, 1};
const ll dy[4] = {-1, 0, 1, 0};
const ll MAX = 2018;

ll N, M;
V<string> S(MAX);
V<V<V<ll>>> dp(MAX, V<V<ll>>(MAX, V<ll>(4, -1)));
// dp[x][y][i] = (x, y)中心で(dx[i], dy[i])方向の
//               突き当たりまでのマス数
// 未探索or壁なら-1

// (x, y)を始点として、方向(dx[i], dy[i])に突き進む
ll dfs(ll x, ll y, ll i) {

    // 再探索防止
    if (dp[x][y][i] >= 0) return dp[x][y][i];

    // 1つ進んだマス(nx, ny)を探索
    ll nx = x + dx[i];
    ll ny = y + dy[i];
    
    if (nx < 0 || nx >= N || ny < 0 || ny >= M || S[nx][ny] != '.') {
        // (nx, ny)は突き当たりなのでマス数は0
        dp[x][y][i] = 0;
    } else {
        // 探索続行
        dp[x][y][i] = dfs(nx, ny, i) + 1;
    }

    return dp[x][y][i];
}


int main() {
    // 初期化
    cin >> N >> M;
    FOR(i, 0, N - 1) {
        cin >> S[i];
    }

    // 方向(dx[i], dy[i])、中継点(x, y)
    FOR(i, 0, 3) {
        FOR(x, 0, N - 1) {
            FOR(y, 0, M - 1) {
                if (S[x][y] == '.') {
                    dfs(x, y, i);
                }
            }
        }
    }

    // 探索結果を集計
    ll ans = 0;
    FOR(x, 0, N - 1) {
        FOR(y, 0, M - 1) {
            if (S[x][y] == '.') {
                ans += (dp[x][y][0] + dp[x][y][2]) * (dp[x][y][1] + dp[x][y][3]);
            }
        }
    }

    cout << ans << endl;
    return 0;
}

提出情報

提出日時
問題 C - 右折
ユーザ Tiramister
言語 C++14 (GCC 5.4.1)
得点 400
コード長 1778 Byte
結果 AC
実行時間 1021 ms
メモリ 290944 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 39
セット名 テストケース
Sample s1.txt, s2.txt, s3.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, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt
ケース名 結果 実行時間 メモリ
01.txt AC 746 ms 290816 KiB
02.txt AC 746 ms 290816 KiB
03.txt AC 747 ms 290816 KiB
04.txt AC 746 ms 290816 KiB
05.txt AC 796 ms 290816 KiB
06.txt AC 794 ms 290816 KiB
07.txt AC 797 ms 290816 KiB
08.txt AC 792 ms 290816 KiB
09.txt AC 961 ms 290944 KiB
10.txt AC 970 ms 290944 KiB
11.txt AC 958 ms 290944 KiB
12.txt AC 962 ms 290944 KiB
13.txt AC 638 ms 290816 KiB
14.txt AC 639 ms 290816 KiB
15.txt AC 1019 ms 290944 KiB
16.txt AC 1021 ms 290944 KiB
17.txt AC 462 ms 290816 KiB
18.txt AC 463 ms 290816 KiB
19.txt AC 583 ms 290816 KiB
20.txt AC 587 ms 290816 KiB
21.txt AC 793 ms 290816 KiB
22.txt AC 793 ms 290816 KiB
23.txt AC 793 ms 290816 KiB
24.txt AC 808 ms 290816 KiB
25.txt AC 814 ms 290944 KiB
26.txt AC 815 ms 290944 KiB
27.txt AC 812 ms 290944 KiB
28.txt AC 812 ms 290944 KiB
29.txt AC 306 ms 286848 KiB
30.txt AC 310 ms 286848 KiB
31.txt AC 305 ms 286848 KiB
32.txt AC 310 ms 286848 KiB
33.txt AC 309 ms 286848 KiB
34.txt AC 306 ms 286848 KiB
35.txt AC 306 ms 286848 KiB
36.txt AC 306 ms 286848 KiB
s1.txt AC 310 ms 286848 KiB
s2.txt AC 308 ms 286848 KiB
s3.txt AC 306 ms 286848 KiB