結果

問題 No.2367 Painting Gascket
ユーザー milanis48663220milanis48663220
提出日時 2023-06-30 23:46:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,713 ms / 2,000 ms
コード長 3,464 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 133,792 KB
実行使用メモリ 53,160 KB
最終ジャッジ日時 2023-09-21 17:56:54
合計ジャッジ時間 27,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,160 KB
testcase_01 AC 6 ms
8,092 KB
testcase_02 AC 21 ms
8,492 KB
testcase_03 AC 4 ms
8,140 KB
testcase_04 AC 4 ms
8,032 KB
testcase_05 AC 4 ms
8,052 KB
testcase_06 AC 4 ms
8,056 KB
testcase_07 AC 4 ms
8,044 KB
testcase_08 AC 1,697 ms
52,960 KB
testcase_09 AC 1,146 ms
38,240 KB
testcase_10 AC 33 ms
8,944 KB
testcase_11 AC 1,506 ms
47,688 KB
testcase_12 AC 34 ms
8,836 KB
testcase_13 AC 458 ms
19,984 KB
testcase_14 AC 231 ms
14,024 KB
testcase_15 AC 227 ms
13,964 KB
testcase_16 AC 602 ms
23,788 KB
testcase_17 AC 1,551 ms
48,944 KB
testcase_18 AC 1,210 ms
39,856 KB
testcase_19 AC 750 ms
27,844 KB
testcase_20 AC 1,540 ms
48,848 KB
testcase_21 AC 867 ms
30,908 KB
testcase_22 AC 1,625 ms
50,816 KB
testcase_23 AC 1,194 ms
39,496 KB
testcase_24 AC 461 ms
20,364 KB
testcase_25 AC 505 ms
21,220 KB
testcase_26 AC 96 ms
10,580 KB
testcase_27 AC 1,263 ms
41,696 KB
testcase_28 AC 1,048 ms
35,576 KB
testcase_29 AC 4 ms
8,040 KB
testcase_30 AC 4 ms
8,028 KB
testcase_31 AC 4 ms
8,080 KB
testcase_32 AC 4 ms
8,024 KB
testcase_33 AC 1,713 ms
52,960 KB
testcase_34 AC 1,704 ms
52,932 KB
testcase_35 AC 1,697 ms
53,016 KB
testcase_36 AC 1,713 ms
53,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint1000000007;
using T = tuple<int, int, int>;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

template<typename T>
class Compress{
    public:
    vector<T> data;
    int offset;
    Compress(vector<T> data_, int offset=0): offset(offset){
        data = data_;
        sort(begin(data), end(data));
        data.erase(unique(begin(data), end(data)), end(data));
    };
    int operator[](T x) {
        auto p = lower_bound(data.begin(), data.end(), x);
        assert(x == *p);
        return offset+(p-data.begin());
	}
    T inv(int x){
        return data[x-offset];
    }
    int size(){
        return data.size();
    }
};

int k, n;

mint memo[100005][3][2][2];
bool ok[100005][3][2][2];

T nx(int a, int b, int x){
    vector<int> v;
    if(a != 0) v.push_back(a);
    if(b != 0) v.push_back(b);
    if(x != 0) v.push_back(x);
    auto cp = Compress<int>(v, 1);
    sort(v.begin(), v.end(), greater<int>());
    int m = cp.size();
    vector<int> ans(3);
    for(int i = 0; i < v.size(); i++){
        ans[i] = cp[v[i]];
    }
    // cout << "=============" << endl;
    // cout << a << ' ' << b << ' ' << x << endl;
    // print_vector(v);
    // print_vector(ans);
    return {ans[0], ans[1], ans[2]};
}

mint solve(int k, int a, int b, int c){
    assert(k != 0);
    if(k == 1){
        return mint(n-a);
    }
    if(ok[k][a][b][c]) return memo[k][a][b][c];
    mint ans = 0;
    assert(b <= a);
    assert(c <= b);
   

    for(int x = 1; x <= 4; x++){
        if(x >= a+2) continue;
        vector<vector<int>> vv = {
            {a, b},  
            {b, c},  
            {c, a},  
        };
        mint pat = [&](){
            if(x <= a) return mint(1);
            else return mint(max(0, n-a));
        }();
        mint tmp = pat;
        for(auto v: vv){
            int a = v[0];
            int b = v[1];
            auto [aa, bb, cc] = nx(a, b, x);
            tmp *= solve(k-1, aa, bb, cc);
        }
        ans += tmp;
    }
    ok[k][a][b][c] = true;
    memo[k][a][b][c] = ans;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> k >> n;
    cout << solve(k+1, 0, 0, 0) << endl;
} 
0