Submission #17629927


Source Code Expand

//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.
 
#ifdef local
#include <bits/extc++.h>
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(args...) qqbx(#args, args)
using ost = std::ostream;
#define DESTL(STL, BEG, END, OUT) \
    template <typename ...T> ost& operator<<(ost &O, std::STL<T...> v) { int f=0; for(auto x: v) O << (f++ ? ", " : BEG) << OUT; return O << END; }
DESTL(deque, "[", "]", x); DESTL(vector, "[", "]", x);
DESTL(set, "{", "}", x); DESTL(multiset, "{", "}", x); DESTL(unordered_set, "{", "}", x);
DESTL(map , "{", "}", x.first << ":" << x.second); DESTL(unordered_map , "{", "}", x.first << ":" << x.second);
template <typename U, typename V> ost& operator<<(ost &O, std::pair<U,V> p) { return O << '(' << p.first << ',' << p.second << ')'; }
template <typename T, size_t N> ost& operator<<(ost &O, std::array<T,N> a) { int f=0; for(T x: a) O << (f++ ? ", " : "[") << x; return O << "]"; }
template <typename T, size_t ...I> ost& prtuple(ost &O, T t, std::index_sequence<I...>) { return (..., (O << (I ? ", " : "(") << std::get<I>(t))), O << ")"; }
template <typename ...T> ost& operator<<(ost &O, std::tuple<T...> t) { return prtuple(O, t, std::make_index_sequence<sizeof...(T)>()); }
template <typename ...T> void qqbx(const char *s, T ...args) {
    int cnt = sizeof...(T);
    (std::cerr << "\033[1;32m(" << s << ") = (" , ... , (std::cerr << args << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) int(lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)
 
using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 2000025, INF = 1e18, MOD = 998244353, K = 19, inf = 1e7;
constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> pw(k+1);
    for(int i = 0; i < n; i++) {
        ll p = 1;
        for(int j = 0; j <= k; j++) {
            pw[j] = (pw[j] + p) % MOD;
            p = p * a[i] % MOD;
        }
    }
    vector<vector<int>> C(k+1, vector<int>(k+1));
    for(int i = 0; i <= k; i++) {
        C[i][0] = 1;
        for(int j = 1; j <= i; j++) {
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
        }
    }
    vector<ll> ans(k+1);
    for(int x = 1; x <= k; x++) {
        debug(C[x]);
        for(int i = 0; i <= x; i++) {
            ll P = (pw[i] * pw[x-i] - pw[x] + MOD) % MOD * modpow(2, MOD-2) % MOD;
            ans[x] = (ans[x] + C[x][i] * P) % MOD;
        }
    }
    for(int i = 1; i <= k; i++) cout << ans[i] << '\n';
}

Submission Info

Submission Time
Task D - Powers
User bingxuan9112
Language C++ (GCC 9.2.1)
Score 600
Code Size 3938 Byte
Status AC
Exec Time 258 ms
Memory 4504 KiB

Compile Error

./Main.cpp:9:1: warning: multi-line comment [-Wcomment]
    9 | //  \###################\
      | ^
./Main.cpp:35: warning: ignoring #pragma loop_opt  [-Wunknown-pragmas]
   35 | #pragma loop_opt(on)
      | 
./Main.cpp: In function ‘constexpr ll cdiv(ll, ll)’:
./Main.cpp:60:56: warning: suggest parentheses around comparison in operand of ‘^’ [-Wparentheses]
   60 | constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
      |                                                       ~^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00_sample_01, 00_sample_02, 00_sample_03
All 00_sample_01, 00_sample_02, 00_sample_03, 10_small_01, 10_small_02, 10_small_03, 10_small_04, 10_small_05, 10_small_06, 10_small_07, 10_small_08, 10_small_09, 10_small_10, 20_random_01, 20_random_02, 20_random_03, 20_random_04, 20_random_05, 20_random_06, 20_random_07, 20_random_08, 20_random_09, 20_random_10, 30_max_01, 30_max_02, 30_max_03, 30_max_04, 30_max_05, 31_max_01, 31_max_02
Case Name Status Exec Time Memory
00_sample_01 AC 14 ms 3484 KiB
00_sample_02 AC 2 ms 3604 KiB
00_sample_03 AC 2 ms 3512 KiB
10_small_01 AC 3 ms 3592 KiB
10_small_02 AC 3 ms 3632 KiB
10_small_03 AC 2 ms 3664 KiB
10_small_04 AC 2 ms 3644 KiB
10_small_05 AC 3 ms 3628 KiB
10_small_06 AC 2 ms 3772 KiB
10_small_07 AC 2 ms 3568 KiB
10_small_08 AC 2 ms 3604 KiB
10_small_09 AC 2 ms 3612 KiB
10_small_10 AC 2 ms 3628 KiB
20_random_01 AC 88 ms 3716 KiB
20_random_02 AC 102 ms 3832 KiB
20_random_03 AC 10 ms 3728 KiB
20_random_04 AC 112 ms 3800 KiB
20_random_05 AC 51 ms 3880 KiB
20_random_06 AC 162 ms 4028 KiB
20_random_07 AC 57 ms 3656 KiB
20_random_08 AC 152 ms 4012 KiB
20_random_09 AC 32 ms 3948 KiB
20_random_10 AC 68 ms 3884 KiB
30_max_01 AC 256 ms 4504 KiB
30_max_02 AC 255 ms 4320 KiB
30_max_03 AC 256 ms 4444 KiB
30_max_04 AC 256 ms 4396 KiB
30_max_05 AC 251 ms 4244 KiB
31_max_01 AC 256 ms 4128 KiB
31_max_02 AC 258 ms 4260 KiB