Submission #19000685


Source Code Expand

//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 305 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
const int N = 42;
int dp[N][N][N][N][N];
ll inv[maxn];
int n, k;
ll solve(int rd, int ls, int rs, int item, int remm) {
	if (dp[rd][ls][rs][item][remm] != -1) 
		return dp[rd][ls][rs][item][remm];
	if (item == 0) return 1;
	int part = 0, rem = 0;
	if (remm > rs) part = 0, rem = remm - rs - 1;
	else part = 1, rem = remm;
	ll ans = 0;
	if (rem == 0) {
		if (part == 0) {
			ll co = item * inv[k - rd] % mod;
			if (co != 1)
				ans = (1 - co) * solve(rd, ls, rs, item, rs) % mod;
		}
		else 
			ans = solve(rd + 1, ls, rs, item, ls + rs + 1);
	} 
	else {
		ll co = item * inv[k - rd] %mod;
		if (part == 0) {
			ans += co * solve(rd, ls - 1, rs, item - 1, rem - 1 + rs + 1);
			ans += (1 - co) * solve(rd, ls, rs, item, rem - 1 + rs + 1);
			ans %= mod;
		} 
		else {
			ans += co * solve(rd, ls, rs - 1, item - 1, rem - 1);
			ans += (1 - co) * solve(rd, ls, rs, item, rem - 1);
			ans %= mod;
		}
	}
	ans %= mod;
	return dp[rd][ls][rs][item][remm] = ans;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < maxn; i++)
		inv[i] = ksm(i, mod - 2);
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < n; i++) {
		ll cur = 1 - solve(0, i, n - i - 1, k, n);
		cur %= mod;
		if (cur < 0) cur += mod;
		cout << cur << endl;
	}
	return 0;
}

Submission Info

Submission Time
Task D - Shopping
User newbiedmy
Language C++ (GCC 9.2.1)
Score 1300
Code Size 1896 Byte
Status AC
Exec Time 332 ms
Memory 514124 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1300 / 1300
Status
AC × 3
AC × 28
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 332 ms 514124 KiB
001.txt AC 301 ms 513984 KiB
002.txt AC 299 ms 513872 KiB
003.txt AC 301 ms 514056 KiB
004.txt AC 300 ms 514032 KiB
005.txt AC 301 ms 514080 KiB
006.txt AC 302 ms 514040 KiB
007.txt AC 304 ms 514016 KiB
008.txt AC 305 ms 514084 KiB
009.txt AC 301 ms 514100 KiB
010.txt AC 309 ms 514100 KiB
011.txt AC 301 ms 513868 KiB
012.txt AC 294 ms 514068 KiB
013.txt AC 298 ms 513832 KiB
014.txt AC 297 ms 514072 KiB
015.txt AC 295 ms 513836 KiB
016.txt AC 302 ms 514068 KiB
017.txt AC 297 ms 513900 KiB
018.txt AC 294 ms 514044 KiB
019.txt AC 298 ms 513904 KiB
020.txt AC 300 ms 513912 KiB
021.txt AC 297 ms 513892 KiB
022.txt AC 296 ms 513876 KiB
023.txt AC 297 ms 514088 KiB
024.txt AC 294 ms 513888 KiB
example0.txt AC 298 ms 513860 KiB
example1.txt AC 296 ms 514040 KiB
example2.txt AC 294 ms 513928 KiB