Submission #18423275


Source Code Expand

#include <iostream>
#include <vector>

using namespace std;


typedef long long int ll;

const ll mod = 1000000000 + 7;

int main() {
    ll h,w; cin >> h >> w;
    vector<string> f(h);
    for (int i = 0; i < h; i++) {
        cin >> f[i];
    }

    vector<vector<ll> > sum_u(h, vector<ll>(w, 0));
    vector<vector<ll> > sum_y(h, vector<ll>(w, 0));
    vector<vector<ll> > sum_n(h, vector<ll>(w, 0));
    vector<vector<ll> > memo(h, vector<ll>(w, 0));
    memo[0][0] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == 0 && j == 0) { continue; }
            if (f[i][j] == '#') {
                memo[i][j] = 0;
                continue;
            }
            // ue
            ll ue = 0;
            if (i > 0 && f[i-1][j] != '#') {
                sum_u[i - 1][j] = (i > 1 ? sum_u[i - 2][j] : 0) + memo[i-1][j];
                ue = sum_u[i-1][j];
            }
            // yoko
            ll yoko = 0;
            if (j > 0 && f[i][j-1] != '#') {
                sum_y[i][j - 1] = (j > 1 ? sum_y[i][j - 2] : 0) + memo[i][j - 1];
                yoko = sum_y[i][j-1];
            }
            // naname
            ll naname = 0;
            if (i > 0 && j > 0 && f[i-1][j-1] != '#') {
                sum_n[i - 1][j - 1] = (i > 1 && j > 1 ? sum_n[i - 2][j - 2] : 0) + memo[i - 1][j - 1];
                naname = sum_n[i - 1][j-1];
            }
            memo[i][j] = (ue + yoko + naname) % mod;
        }
    }
    cout << memo[h-1][w-1] << endl;
    return 0;
}

Submission Info

Submission Time
Task E - Queen on Grid
User tomoya
Language C++ (Clang 10.0.0)
Score 500
Code Size 1579 Byte
Status AC
Exec Time 242 ms
Memory 134360 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 242 ms 134332 KiB
random_02.txt AC 82 ms 41492 KiB
random_03.txt AC 223 ms 134280 KiB
random_04.txt AC 97 ms 48952 KiB
random_05.txt AC 233 ms 134280 KiB
random_06.txt AC 37 ms 20504 KiB
random_07.txt AC 239 ms 134360 KiB
random_08.txt AC 34 ms 15372 KiB
random_09.txt AC 224 ms 134324 KiB
random_10.txt AC 34 ms 17992 KiB
random_11.txt AC 235 ms 134300 KiB
random_12.txt AC 8 ms 4092 KiB
random_13.txt AC 221 ms 134304 KiB
random_14.txt AC 211 ms 132668 KiB
random_15.txt AC 197 ms 134176 KiB
sample_01.txt AC 2 ms 3148 KiB
sample_02.txt AC 2 ms 3144 KiB
sample_03.txt AC 2 ms 3064 KiB