結果

問題 No.2310 [Cherry 5th Tune A] Against Regret
ユーザー milanis48663220milanis48663220
提出日時 2023-05-19 23:34:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,645 ms / 6,000 ms
コード長 3,868 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 134,812 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-08-23 01:28:34
合計ジャッジ時間 27,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 115 ms
4,380 KB
testcase_09 AC 238 ms
4,400 KB
testcase_10 AC 351 ms
4,380 KB
testcase_11 AC 567 ms
4,376 KB
testcase_12 AC 525 ms
4,380 KB
testcase_13 AC 260 ms
4,380 KB
testcase_14 AC 327 ms
4,380 KB
testcase_15 AC 628 ms
4,376 KB
testcase_16 AC 60 ms
4,380 KB
testcase_17 AC 309 ms
4,380 KB
testcase_18 AC 1,618 ms
4,620 KB
testcase_19 AC 1,630 ms
4,660 KB
testcase_20 AC 1,623 ms
4,704 KB
testcase_21 AC 1,619 ms
4,668 KB
testcase_22 AC 1,617 ms
4,612 KB
testcase_23 AC 1,613 ms
4,648 KB
testcase_24 AC 1,627 ms
4,652 KB
testcase_25 AC 1,645 ms
4,676 KB
testcase_26 AC 1,613 ms
4,740 KB
testcase_27 AC 1,640 ms
4,720 KB
testcase_28 AC 1,616 ms
4,616 KB
testcase_29 AC 371 ms
4,380 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;
}

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();
    }
};

using mint = atcoder::modint998244353;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    auto x = vec2d(n+1, n+1, mint(0));
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            int y; cin >> y;
            x[i][j] = y;
        }
    }
    auto dp = vec2d(n+1, n+1, mint(0));
    for(int s = n; s >= 0; s--){
        for(int t = s+1; t <= n; t++){
            for(int c = s+1; c < t; c++){
                dp[s][t] += x[s][c]*dp[c][t];
            }
            dp[s][t] += x[s][t];
        }
    }
    int q; cin >> q;
    while(q--){
        int k; cin >> k;
        vector<int> v = {0, n};
        vector<int> a(k), b(k), c(k);
        for(int i = 0; i < k; i++){
            cin >> a[i] >> b[i] >> c[i];
            v.push_back(a[i]);
            v.push_back(b[i]);
        }
        auto cp = Compress<int>(v);
        int m = cp.size();
        auto xx = vec2d(m, m, mint(0));
        auto yy = vec2d(m, m, mint(0));
        for(int i = 0; i < m; i++){
            int s = cp.data[i];
            for(int j = 0; j < m; j++){
                int t = cp.data[j];
                xx[i][j] = dp[s][t];
            }
        }
        for(int i = 0; i < k; i++){
            int s = cp[a[i]];
            int t = cp[b[i]];
            yy[s][t] += c[i];
        }
        // cout << "=====" << endl;
        // for(int i = 0; i < m; i++) print_vector(xx[i]);
        // cout << "=====" << endl;
        // for(int i = 0; i < m; i++) print_vector(yy[i]);
        // print_vector(v);
        auto dp = vec2d(m, 2, mint(0));
        dp[0][1] = 1;
        for(int i = 0; i < m; i++){
            for(int j = 0; j < m; j++){
                // 元の道
                dp[j][0] += dp[i][1]*xx[i][j];
                // 新たな道
                dp[j][1] += dp[i][0]*yy[i][j];
                dp[j][1] += dp[i][1]*yy[i][j];
            }
            // print_vector(dp[i]);
        }
        cout << dp[m-1][0]+dp[m-1][1] << endl;
    }
}
0