結果

問題 No.2810 Have Another Go (Hard)
ユーザー ぷらぷら
提出日時 2024-07-12 21:45:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,277 ms / 3,000 ms
コード長 5,148 bytes
コンパイル時間 1,738 ms
コンパイル使用メモリ 150,844 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-12 21:46:16
合計ジャッジ時間 45,396 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 853 ms
6,940 KB
testcase_02 AC 856 ms
6,940 KB
testcase_03 AC 854 ms
6,940 KB
testcase_04 AC 873 ms
6,940 KB
testcase_05 AC 854 ms
6,944 KB
testcase_06 AC 854 ms
6,940 KB
testcase_07 AC 885 ms
6,940 KB
testcase_08 AC 859 ms
6,940 KB
testcase_09 AC 878 ms
6,940 KB
testcase_10 AC 880 ms
6,944 KB
testcase_11 AC 7 ms
6,944 KB
testcase_12 AC 7 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 6 ms
6,940 KB
testcase_16 AC 249 ms
6,944 KB
testcase_17 AC 1,102 ms
6,940 KB
testcase_18 AC 661 ms
6,944 KB
testcase_19 AC 1,014 ms
6,944 KB
testcase_20 AC 148 ms
6,940 KB
testcase_21 AC 335 ms
6,940 KB
testcase_22 AC 605 ms
6,940 KB
testcase_23 AC 458 ms
6,940 KB
testcase_24 AC 775 ms
6,940 KB
testcase_25 AC 1,103 ms
6,940 KB
testcase_26 AC 1,250 ms
6,944 KB
testcase_27 AC 1,252 ms
6,940 KB
testcase_28 AC 1,277 ms
6,944 KB
testcase_29 AC 1,224 ms
6,944 KB
testcase_30 AC 1,222 ms
6,940 KB
testcase_31 AC 1,247 ms
6,944 KB
testcase_32 AC 1,231 ms
6,944 KB
testcase_33 AC 1,223 ms
6,940 KB
testcase_34 AC 1,200 ms
6,944 KB
testcase_35 AC 1,177 ms
6,940 KB
testcase_36 AC 1,198 ms
6,940 KB
testcase_37 AC 1,227 ms
6,940 KB
testcase_38 AC 1,172 ms
6,944 KB
testcase_39 AC 1,200 ms
6,944 KB
testcase_40 AC 1,196 ms
6,944 KB
testcase_41 AC 1,200 ms
6,944 KB
testcase_42 AC 1,226 ms
6,944 KB
testcase_43 AC 1,224 ms
6,944 KB
testcase_44 AC 1,209 ms
6,944 KB
testcase_45 AC 1,252 ms
6,940 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 4 ms
6,940 KB
testcase_48 AC 7 ms
6,944 KB
testcase_49 AC 4 ms
6,944 KB
testcase_50 AC 5 ms
6,944 KB
testcase_51 AC 155 ms
6,944 KB
testcase_52 AC 98 ms
6,940 KB
testcase_53 AC 226 ms
6,944 KB
testcase_54 AC 303 ms
6,940 KB
testcase_55 AC 106 ms
6,940 KB
testcase_56 AC 264 ms
6,944 KB
testcase_57 AC 192 ms
6,948 KB
testcase_58 AC 149 ms
6,944 KB
testcase_59 AC 400 ms
6,944 KB
testcase_60 AC 218 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template<class T> using pq = priority_queue<T,vector<T>,greater<T>>;
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }

int dx4[] = {1,0,-1,0};
int dy4[] = {0,1,0,-1};

#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf)
#define REP1(i, n) for(ll i = 0; i < (n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf)
#define per1(i, n) for(ll i = (n)-1; i >= 0; --i)
#define per2(i, a, b) for(ll i = (a)-1; i >= b; --i)
#define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c))
#define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__)
#define setbits(j, n) for(ll iiiii = (n), j = lowbit(iiiii); iiiii; iiiii ^= 1 << j, j = lowbit(iiiii))
#define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(all(v)));)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define drop(s) cout << #s << endl, exit(0)
#define si(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
#define rng(v, l, r) v.begin() + (l), v.begin() + (r)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))

constexpr int mod = 998244353;

vector<vector<int>> Mul(vector<vector<int>> A,vector<vector<int>> B) {
    vector<vector<int>>ans(A.size(),vector<int>(A.size()));
    for(int i = 0; i < A.size(); i++) {
        for(int j = 0; j < A.size(); j++) {
            for(int k = 0; k < A.size(); k++) {
                ans[i][j] += 1ll*A[i][k]*B[k][j]%mod;
                if(ans[i][j] >= mod) ans[i][j] -= mod;
            }
        }
    }
    return ans;
}

vector<vector<int>> Pow(vector<vector<int>> A,long long B) {
    vector<vector<int>>ans(A.size(),vector<int>(A.size()));
    for(int i = 0; i < A.size(); i++) {
        ans[i][i] = 1;
    }
    while (B) {
        if(1 & B) {
            ans = Mul(ans,A);
        }
        A = Mul(A,A);
        B /= 2;
    }
    return ans;
}

void mpl(int &x,int y) {
    x += y;
    if(x >= mod) x -= mod;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,k;
    cin >> n >> m >> k;
    vc<int>C(k);
    rep(i,k) {
        cin >> C[i];
    }
    vvc<int>x(6,vc<int>(6));
    rep(i,6) {
        x[0][i] = 1;
        if(i) x[i][i-1] = 1;
    }
    x = Pow(x,1ll*n*m);
    int sum = 0;
    rep(i,6) {
        mpl(sum,x[0][i]);
    }
    rep(i,k) {
        vvc<int>ans(6,vc<int>(6));
        vvc<int>a(6,vc<int>(6));
        rep(i,6) {
            a[0][i] = 1;
            if(i) a[i][i-1] = 1;
        }
        a = Pow(a,C[i]);
        ans[0][0] = 1;
        ans = Mul(ans,a);
        ans[0][0] = 0;
        vvc<int>b(6,vc<int>(6));
        rep(i,6) {
            b[0][i] = 1;
            if(i) b[i][i-1] = 1;
        }
        b = Pow(b,n);
        rep(i,6) {
            b[i][0] = 0;
        }
        b = Pow(b,m-1);
        ans = Mul(ans,b);
        vvc<int>c(6,vc<int>(6));
        rep(i,6) {
            c[0][i] = 1;
            if(i) c[i][i-1] = 1;
        }
        c = Pow(c,n-C[i]);
        ans = Mul(ans,c);
        int fans = 0;
        rep(i,6) {
            mpl(fans,ans[0][i]);
        }
        fans = (sum+mod-fans)%mod;
        cout << fans << "\n";
    }
}
0