結果

問題 No.220 世界のなんとか2
ユーザー kimiyukikimiyuki
提出日時 2016-12-13 18:19:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,472 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 91,600 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 02:03:14
合計ジャッジ時間 2,090 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
ll bit(int i) { return 1ll << i; }
const int dy[] = { -1, 1, 0, 0 };
const int dx[] = { 0, 0, 1, -1 };
bool is_on_field(int y, int x, int h, int w) { return 0 <= y and y < h and 0 <= x and x < w; }
int main() {
    int p; cin >> p;
    vector<vector<vector<ll> > > dp = vectors(p+1, 2, 3, ll());
    dp[0][0][0] = 1;
    repeat (i,p) {
        dp[i+1][1][0] =
            + dp[i][1][0] * 4 /* 0, 3, 6, 9 */
            + dp[i][1][1] * 3 /* 2, 5, 8 */
            + dp[i][1][2] * 3 /* 1, 4, 7 */
            + dp[i][0][0]; /* 3 */
        dp[i+1][1][1] =
            + dp[i][1][0] * 3 /* 1, 4, 7 */
            + dp[i][1][1] * 4 /* 0, 3, 6, 9 */
            + dp[i][1][2] * 3 /* 2, 5, 8 */
            + dp[i][0][1]; /* 3 */
        dp[i+1][1][2] =
            + dp[i][1][0] * 3
            + dp[i][1][1] * 3
            + dp[i][1][2] * 4
            + dp[i][0][2]; /* 3 */
        dp[i+1][0][0] =
            + dp[i][0][0] * 3 /* 0, 6, 9 */
            + dp[i][0][1] * 3
            + dp[i][0][2] * 3;
        dp[i+1][0][1] =
            + dp[i][0][0] * 3 /* 0, 6, 9 */
            + dp[i][0][1] * 3
            + dp[i][0][2] * 3;
        dp[i+1][0][2] =
            + dp[i][0][0] * 3 /* 0, 6, 9 */
            + dp[i][0][1] * 3
            + dp[i][0][2] * 3;
    }
    ll ans =
        + dp[p][1][0]
        + dp[p][1][1]
        + dp[p][1][2]
        + dp[p][0][0] - 1;
    cout << ans << endl;
    return 0;
}
0