Language: C++

#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000000007;
using ll = long long;

// return a^n % mod
ll mod_pow(ll a, ll n) {
    if(n == 0) return 1;
    ll ret = 0;
    ll tmp = a;
    while(n > 0) {
        if(n % 2) {
            ret += tmp;
            ret %= mod;
        }
        tmp = tmp * tmp;
        tmp %= mod;
        n /= 2;
    }
    return ret;
}

int main () {
    int n, m;
    cin >> n >> m;
    if(n == 1) {
        cout << mod_pow(2, m) << endl;
        return 0;
    }
    if(m == 1) {
        cout << 4 << endl;
        return 0;
    }
    n--; m--;
    if(n == 1) {
        ll ans = 0, tmp = 1;
        for(int i = 1; i <= m; i++) {
            ans += 2 * tmp * mod_pow(3, m - i); ans %= mod;
            tmp *= 2; tmp %= mod;
        }
        ans += tmp;
        cout << 4 * ans << endl;
        return 0;
    }
    vector<vector<vector<>> dp(m + 1, vector<vector<int>>(n + 1, vector<int>(2, 0)));
    for(int i = 1; i <= m; i++) for(int j = 0; j <= n; j++) for(int k = 0; k <= 1; k++) {
        if(i == 1) { // 初期条件
            if(k == 1) {
                if(j == 0) dp[i][j][k] = 2;
                if(j == 1) dp[i][j][k] = 1;
            } else {
                if(j == 0) dp[i][j][k] = 1;
                else if(j == n) dp[i][j][k] = 3;
                else if(j == 1) dp[i][j][k] = 3;
                else dp[i][j][k] = 4;
            }
        } else { // 遷移
            ll val = 0;
            if(k == 1) {
                if(j == 0) val = 2LL * (dp[i - 1][j][0] + dp[i - 1][j][1]) + dp[i - 1][j + 1][1];
                else if(j == n) val = 2LL * dp[i - 1][j][1] + dp[i - 1][j - 1][1];
                else if(j == 1) val = 2LL * dp[i - 1][j][1] + (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) + dp[i - 1][j + 1][1];
                else val = 2LL * dp[i - 1][j][1] + dp[i - 1][j - 1][1] + dp[i - 1][j + 1][1];
            } else {
                if(j == 0) val = dp[i - 1][j + 1][0];
                else if(j == n) val = 2LL * dp[i - 1][j][0] + dp[i - 1][j - 1][0];
                else if(j == 1) val = 2LL * dp[i - 1][j][0] + dp[i - 1][j + 1][0];
                else val = 2LL * dp[i - 1][j][0] + dp[i - 1][j - 1][0] + dp[i - 1][j + 1][0];
            }
            dp[i][j][k] = val % mod;
        }
    }
    ll ans = 0;
    for(int i = 0; i <= n; i++) ans += dp[m][i][1];
    ans += dp[m][0][0];
    cout << (4LL * ans) % mod << endl; // 問題の言い換えで答えが 1/4 になっていたので
}


Compiler output:
a.cc: In function 'int main()':
a.cc:45:25: error: wrong number of template arguments (0, should be at least 1)
   45 |     vector<vector<vector<>> dp(m + 1, vector<vector<int>>(n + 1, vector<int>(2, 0)));
      |                         ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:428:11: note: provided for 'template<class _Tp, class _Alloc> class std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:45:26: error: template argument 1 is invalid
   45 |     vector<vector<vector<>> dp(m + 1, vector<vector<int>>(n + 1, vector<int>(2, 0)));
      |                          ^~
a.cc:45:26: error: template argument 2 is invalid
a.cc:45:84: error: template argument 1 is invalid
   45 |     vector<vector<vector<>> dp(m + 1, vector<vector<int>>(n + 1, vector<int>(2, 0)));
      |                                                                                    ^
a.cc:45:84: error: template argument 2 is invalid
a.cc:49:28: error: 'dp' was not declared in this scope; did you mean 'dup'?
   49 |                 if(j == 0) dp[i][j][k] = 2;
      |                            ^~
      |                            dup
a.cc:50:28: error: 'dp' was not declared in this scope; did you mean 'dup'?
   50 |                 if(j == 1) dp[i][j][k] = 1;
      |                            ^~
      |                            dup
a.cc:52:28: error: 'dp' was not declared in this scope; did you mean 'dup'?
   52 |                 if(j == 0) dp[i][j][k] = 1;
      |                            ^~
      |                            dup
a.cc:53:33: error: 'dp' was not declared in this scope; did you mean 'dup'?
   53 |                 else if(j == n) dp[i][j][k] = 3;
      |                                 ^~
      |                                 dup
a.cc:54:33: error: 'dp' was not declared in this scope; did you mean 'dup'?
   54 |                 else if(j == 1) dp[i][j][k] = 3;
      |                                 ^~
      |                                 dup
a.cc:55:22: error: 'dp' was not declared in this scope; did you mean 'dup'?
   55 |                 else dp[i][j][k] = 4;
      |                      ^~
      |                      dup
a.cc:60:41: error: 'dp' was not declared in this scope; did you mean 'dup'?
   60 |                 if(j == 0) val = 2LL * (dp[i - 1][j][0] + dp[i - 1][j][1]) + dp[i - 1][j + 1][1];
      |                                         ^~
      |                                         dup
a.cc:61:45: error: 'dp' was not declared in this scope; did you mean 'dup'?
   61 |                 else if(j == n) val = 2LL * dp[i - 1][j][1] + dp[i - 1][j - 1][1];
      |                                             ^~
      |                                             dup
a.cc:62:45: error: 'dp' was not declared in this scope; did you mean 'dup'?
   62 |                 else if(j == 1) val = 2LL * dp[i - 1][j][1] + (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) + dp[i - 1][j + 1][1];
      |                                             ^~
      |                                             dup
a.cc:63:34: error: 'dp' was not declared in this scope; did you mean 'dup'?
   63 |                 else val = 2LL * dp[i - 1][j][1] + dp[i - 1][j - 1][1] + dp[i - 1][j + 1][1];
      |                                  ^~
      |                                  dup
a.cc:65:34: error: 'dp' was not declared in this scope; did you mean 'dup'?
   65 |                 if(j == 0) val = dp[i - 1][j + 1][0];
      |                                  ^~
      |                                  dup
a.cc:66:45: error: 'dp' was not declared in this scope; did you mean 'dup'?
   66 |                 else if(j == n) val = 2LL * dp[i - 1][j][0] + dp[i - 1][j - 1][0];
      |                                             ^~
      |                                             dup
a.cc:67:45: error: 'dp' was not declared in this scope; did you mean 'dup'?
   67 |                 else if(j == 1) val = 2LL * dp[i - 1][j][0] + dp[i - 1][j + 1][0];
      |                                             ^~
      |                                             dup
a.cc:68:34: error: 'dp' was not declared in this scope; did you mean 'dup'?
   68 |                 else val = 2LL * dp[i - 1][j][0] + dp[i - 1][j - 1][0] + dp[i - 1][j + 1][0];
      |                                  ^~
      |                                  dup
a.cc:70:13: error: 'dp' was not declared in this scope; did you mean 'dup'?
   70 |             dp[i][j][k] = val % mod;
      |             ^~
      |             dup
a.cc:74:40: error: 'dp' was not declared in this scope; did you mean 'dup'?
   74 |     for(int i = 0; i <= n; i++) ans += dp[m][i][1];
      |                                        ^~
      |                                        dup
a.cc:75:12: error: 'dp' was not declared in this scope; did you mean 'dup'?
   75 |     ans += dp[m][0][0];
      |            ^~
      |            dup