Submission #65320388


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define fre(x) freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout)
#define ck(x)  { cout << "check " << x << endl;}
#define int long long
#define double long double
#define inf 0x3fffffffffffffff

template<class T>
constexpr T power(T a, int b) {
    T res = 1;
    for (; b; b /= 2, a *= a)
        if (b % 2) res *= a;
    return res;
}
constexpr int mul(int a, int b, int p) {
    int res = a * b % p;
    if (res < 0) res += p;
    return res;
}
template<int P>
struct MInt {
    int x;
    constexpr MInt() : x{} {}
    constexpr MInt(int x) : x{norm(x % getMod())} {}
    static int Mod;
    constexpr static int getMod() { return P > 0 ? P : Mod;}
    constexpr static void setMod(int Mod_) { Mod = Mod_;}
    constexpr int norm(int x) const { if (x < 0) x += getMod(); if (x >= getMod()) x -= getMod(); return x;}
    constexpr int val() const { return x;}
    explicit constexpr operator int() const { return x;}
    constexpr MInt operator-() const { MInt res; res.x = norm(getMod() - x); return res;}
    constexpr MInt inv() const { assert(x != 0); return power(*this, getMod() - 2);}
    constexpr MInt &operator*=(MInt rhs) & { x = mul(x, rhs.x, getMod()); return *this;}
    constexpr MInt &operator+=(MInt rhs) & { x = norm(x + rhs.x); return *this;}
    constexpr MInt &operator-=(MInt rhs) & { x = norm(x - rhs.x); return *this;}
    constexpr MInt &operator/=(MInt rhs) & { return *this *= rhs.inv();}
    friend constexpr MInt operator*(MInt lhs, MInt rhs) { MInt res = lhs; res *= rhs; return res;}
    friend constexpr MInt operator+(MInt lhs, MInt rhs) { MInt res = lhs; res += rhs; return res;}
    friend constexpr MInt operator-(MInt lhs, MInt rhs) { MInt res = lhs; res -= rhs; return res;}
    friend constexpr MInt operator/(MInt lhs, MInt rhs) { MInt res = lhs; res /= rhs; return res;}
    friend constexpr istream &operator>>(istream &is, MInt &a) { int v; is >> v; a = MInt(v); return is;}
    friend constexpr ostream &operator<<(ostream &os, const MInt &a) { return os << a.val();}
    friend constexpr bool operator==(MInt lhs, MInt rhs) { return lhs.val() == rhs.val();}
    friend constexpr bool operator!=(MInt lhs, MInt rhs) { return lhs.val() != rhs.val();}
};

template<>
int MInt<0>::Mod = 998244353;

template<int V, int P>
constexpr MInt<P> CInv = MInt<P>(V).inv();

constexpr int modp = 998244353;
using Z = MInt<modp>;

// template<int P>
// int MInt<P>::Mod = P;

// using Z = MInt<0>;
// Z::setMod(mod);

Z qpow(Z k, int n) {
	Z s = 1;
	for ( ; n; n >>= 1, k = k * k) 
		if(n & 1) s = s * k;
	return s;
}

struct math {
	int size = 0;
	vector<Z> fac, inv;
	math(int n = 0) {
		init(n);
	}
	void init(int n) {
		fac.resize(n + 2);
		inv.resize(n + 2);
		fac[0] = 1;
		for (int i = size + 1; i <= n; i++) {
			fac[i] = fac[i - 1] * i;
		}
		inv[n] = qpow(fac[n], modp - 2);
		for (int i = n; i >= size + 1; i--) {
			inv[i - 1] = inv[i] * i;
		}
		size = n;
	}
	Z C(int n, int m) {
		if (n < m || m < 0) return 0;
		if(n > size) init(n);
		return fac[n] * inv[m] * inv[n - m];
	}
} binom;

Z C(int n, int m) {
	return binom.C(n, m); 
}
Z C(Z n, Z m) {
	return binom.C(n.val(), m.val()); 
}
Z fac(int n) {
	if (binom.size < n) binom.init(n);
	return binom.fac[n];
}
Z bfC(int n, int m) {
	if (n < m || m < 0) return 0;
	Z s = 1;
	for (int i = n - m + 1; i <= n; i++) {
		s *= i;
	}
	return s / fac(m);
}


//-------------- templates above --------------


void solve() {
	int n, k;
	cin >> n >> k;
	vector<Z> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] += a[i - 1];
	}
	vector s(n + 1, vector<Z>(k + 1));
	for (int i = 0; i <= n; i++) {
		s[i][0] = 1;
		for (int j = 1; j <= k; j++) {
			s[i][j] = s[i][j - 1] * a[i];
		}
	}
	auto ss = s;
	for (int i = 0; i <= k; i++) {
		for (int j = 1; j <= n; j++) {
			ss[j][i] += ss[j - 1][i];
		}
	}
	Z ans = 0;
	for (int i = 0; i <= k; i++) {
		Z res = 0;
		for (int r = 1; r <= n; r++) {
			res += s[r][i] * ss[r - 1][k - i];
		}
		ans += ((k - i) & 1 ? -1 : 1) * C(k, i) * res;
	}
	cout << ans << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T = 1;
	while (T--) {
		solve();
	}
	return 0;
}

Submission Info

Submission Time
Task F - Range Power Sum
User KisuraOP
Language C++ 20 (gcc 12.2)
Score 550
Code Size 4350 Byte
Status AC
Exec Time 81 ms
Memory 51776 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 3
AC × 44
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 03_minmax_00.txt, 03_minmax_01.txt, 03_minmax_02.txt, 03_minmax_03.txt, 03_minmax_04.txt, 03_minmax_05.txt, 03_minmax_06.txt, 03_minmax_07.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3580 KiB
00_sample_01.txt AC 1 ms 3448 KiB
00_sample_02.txt AC 1 ms 3420 KiB
01_random_00.txt AC 2 ms 4100 KiB
01_random_01.txt AC 31 ms 26544 KiB
01_random_02.txt AC 30 ms 26448 KiB
01_random_03.txt AC 24 ms 20260 KiB
01_random_04.txt AC 32 ms 26520 KiB
01_random_05.txt AC 32 ms 26452 KiB
01_random_06.txt AC 26 ms 23504 KiB
01_random_07.txt AC 37 ms 33012 KiB
01_random_08.txt AC 36 ms 32864 KiB
01_random_09.txt AC 26 ms 22816 KiB
01_random_10.txt AC 38 ms 32920 KiB
01_random_11.txt AC 41 ms 32744 KiB
01_random_12.txt AC 6 ms 7520 KiB
01_random_13.txt AC 45 ms 39024 KiB
01_random_14.txt AC 45 ms 39012 KiB
01_random_15.txt AC 22 ms 20020 KiB
01_random_16.txt AC 47 ms 38968 KiB
01_random_17.txt AC 47 ms 38932 KiB
01_random_18.txt AC 31 ms 26556 KiB
01_random_19.txt AC 58 ms 45192 KiB
01_random_20.txt AC 60 ms 45200 KiB
01_random_21.txt AC 27 ms 23624 KiB
01_random_22.txt AC 58 ms 45212 KiB
01_random_23.txt AC 60 ms 45256 KiB
01_random_24.txt AC 6 ms 7332 KiB
01_random_25.txt AC 69 ms 51588 KiB
01_random_26.txt AC 75 ms 51608 KiB
01_random_27.txt AC 46 ms 36588 KiB
01_random_28.txt AC 68 ms 51604 KiB
01_random_29.txt AC 70 ms 51528 KiB
02_random2_00.txt AC 69 ms 51604 KiB
02_random2_01.txt AC 81 ms 51588 KiB
02_random2_02.txt AC 78 ms 51776 KiB
03_minmax_00.txt AC 1 ms 3584 KiB
03_minmax_01.txt AC 1 ms 3496 KiB
03_minmax_02.txt AC 1 ms 3460 KiB
03_minmax_03.txt AC 1 ms 3504 KiB
03_minmax_04.txt AC 26 ms 26616 KiB
03_minmax_05.txt AC 31 ms 26452 KiB
03_minmax_06.txt AC 74 ms 51604 KiB
03_minmax_07.txt AC 78 ms 51604 KiB