提出 #18997655
ソースコード 拡げる
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const ll MOD = 998244353;
ll add(ll x, ll y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
ll sub(ll x, ll y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
ll mult(ll x, ll y) {
return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
if (p == 0) return 1;
if (p & 1) return mult(x, bin_pow(x, p - 1));
return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
return bin_pow(x, MOD - 2);
}
const int N = 42;
int n, k;
int dd[N][N];
int ANS;
int dp[2][N][N][N][N];
void solve(int PP) {
for (int f = 0; f < 2; f++)
for (int i = 0; i <= n; i++)
for (int x = 0; x <= n; x++)
for (int y = 0; y <= n; y++)
for (int z = 0; z <= n; z++)
dp[f][i][x][y][z] = 0;
dp[0][0][0][PP][n - 1 - PP] = 1;
for (int m = 0; m <= n; m++) {
for (int x = 0; x <= n; x++)
for (int y = n; y >= 0; y--)
for (int z = 0; z <= n; z++) {
if (dp[0][m][x][y][z] == 0) continue;
int prizes = k - (n - x - y - z - 1);
if (prizes <= 0) continue;
if (y == 0) {
int Q = dd[prizes][k - m];
ANS = add(ANS, mult(Q, dp[0][m][x][y][z]));
Q = sub(1, Q);
dp[1][m][0][z][x] = add(dp[1][m][0][z][x], mult(Q, dp[0][m][x][y][z]));
} else {
int Q = dd[prizes][k - m];
dp[0][m][x][y - 1][z] = add(dp[0][m][x][y - 1][z], mult(Q, dp[0][m][x][y][z]));
Q = sub(1, Q);
dp[0][m][x + 1][y - 1][z] = add(dp[0][m][x + 1][y - 1][z], mult(Q, dp[0][m][x][y][z]));
}
}
for (int x = 0; x <= n; x++)
for (int y = n; y >= 0; y--)
for (int z = 0; z <= n; z++) {
if (dp[1][m][x][y][z] == 0) continue;
int prizes = k - (n - x - y - z - 1);
if (prizes <= 0) continue;
if (y == 0) {
dp[0][m + 1][0][z][x] = add(dp[0][m + 1][0][z][x], dp[1][m][x][y][z]);
} else {
int Q = dd[prizes][k - m];
dp[1][m][x][y - 1][z] = add(dp[1][m][x][y - 1][z], mult(Q, dp[1][m][x][y][z]));
Q = sub(1, Q);
dp[1][m][x + 1][y - 1][z] = add(dp[1][m][x + 1][y - 1][z], mult(Q, dp[1][m][x][y][z]));
}
}
}
}
int main()
{
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
for (int i = 0; i < N; i++)
for (int j = 1; j < N; j++)
dd[i][j] = mult(i, rev(j));
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
ANS = 0;
solve(i);
printf("%d ", ANS);
printf("\n");
}
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
D - Shopping |
| ユーザ |
Um_nik |
| 言語 |
C++ (GCC 9.2.1) |
| 得点 |
1300 |
| コード長 |
3559 Byte |
| 結果 |
AC |
| 実行時間 |
564 ms |
| メモリ |
27296 KiB |
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:139:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
139 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
1300 / 1300 |
| 結果 |
|
|
| セット名 |
テストケース |
| 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 |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 000.txt |
AC |
564 ms |
27296 KiB |
| 001.txt |
AC |
540 ms |
27200 KiB |
| 002.txt |
AC |
544 ms |
27200 KiB |
| 003.txt |
AC |
560 ms |
27084 KiB |
| 004.txt |
AC |
540 ms |
27200 KiB |
| 005.txt |
AC |
553 ms |
27240 KiB |
| 006.txt |
AC |
548 ms |
27296 KiB |
| 007.txt |
AC |
536 ms |
27112 KiB |
| 008.txt |
AC |
558 ms |
27196 KiB |
| 009.txt |
AC |
544 ms |
27064 KiB |
| 010.txt |
AC |
541 ms |
27192 KiB |
| 011.txt |
AC |
545 ms |
27188 KiB |
| 012.txt |
AC |
4 ms |
3624 KiB |
| 013.txt |
AC |
3 ms |
3764 KiB |
| 014.txt |
AC |
4 ms |
3832 KiB |
| 015.txt |
AC |
6 ms |
4964 KiB |
| 016.txt |
AC |
261 ms |
21792 KiB |
| 017.txt |
AC |
335 ms |
23876 KiB |
| 018.txt |
AC |
43 ms |
10928 KiB |
| 019.txt |
AC |
24 ms |
9248 KiB |
| 020.txt |
AC |
113 ms |
16208 KiB |
| 021.txt |
AC |
430 ms |
25068 KiB |
| 022.txt |
AC |
342 ms |
22820 KiB |
| 023.txt |
AC |
281 ms |
21896 KiB |
| 024.txt |
AC |
251 ms |
20844 KiB |
| example0.txt |
AC |
3 ms |
3780 KiB |
| example1.txt |
AC |
4 ms |
3960 KiB |
| example2.txt |
AC |
530 ms |
27084 KiB |