結果

問題 No.1513 simple 門松列 problem
ユーザー kwm_tkwm_t
提出日時 2021-05-22 16:23:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 3,000 ms
コード長 2,089 bytes
コンパイル時間 4,082 ms
コンパイル使用メモリ 226,860 KB
実行使用メモリ 68,176 KB
最終ジャッジ日時 2024-04-18 21:10:28
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
67,788 KB
testcase_01 AC 19 ms
68,172 KB
testcase_02 AC 83 ms
67,920 KB
testcase_03 AC 18 ms
67,912 KB
testcase_04 AC 19 ms
67,788 KB
testcase_05 AC 18 ms
67,920 KB
testcase_06 AC 18 ms
67,784 KB
testcase_07 AC 20 ms
67,920 KB
testcase_08 AC 19 ms
68,044 KB
testcase_09 AC 18 ms
67,916 KB
testcase_10 AC 18 ms
68,044 KB
testcase_11 AC 18 ms
68,044 KB
testcase_12 AC 18 ms
67,916 KB
testcase_13 AC 18 ms
68,044 KB
testcase_14 AC 84 ms
68,044 KB
testcase_15 AC 84 ms
68,048 KB
testcase_16 AC 83 ms
68,176 KB
testcase_17 AC 60 ms
67,912 KB
testcase_18 AC 31 ms
67,916 KB
testcase_19 AC 19 ms
67,916 KB
testcase_20 AC 27 ms
68,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
mint dp1[202][202][202];
mint dp2[202][202][202];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m; cin >> n >> m;
	rep(i, m) rep(j, m) dp1[0][i][j] = 1;
	rep(i, m) rep(j, m) dp2[0][i][j] = i + j;
	rep(i, m)dp1[0][i][i] = 0;
	rep(i, m)dp2[0][i][i] = 0;
	rep(i, n - 2) {
		rep(j, m) {
			//a>bの前計算
			mint memo1 = 0;
			rep2(k, j + 1, m) memo1 += dp1[i][k][j];
			mint memo2 = 0;
			rep2(k, j + 1, m) memo2 += dp2[i][k][j];
			rep2(k, j + 1, m) {
				//a>b<c
				dp1[i + 1][j][k] += memo1;
				dp1[i + 1][j][k] -= dp1[i][k][j];

				dp2[i + 1][j][k] += memo2;
				dp2[i + 1][j][k] -= dp2[i][k][j];
				dp2[i + 1][j][k] += k * dp1[i + 1][j][k];
			}
		}
		rep(j, m) {
			//a<bの前計算
			mint memo1 = 0;
			rep(k, j) memo1 += dp1[i][k][j];
			mint memo2 = 0;
			rep(k, j) memo2 += dp2[i][k][j];
			rep(k, j) {
				//a<b>c
				dp1[i + 1][j][k] += memo1;
				dp1[i + 1][j][k] -= dp1[i][k][j];

				dp2[i + 1][j][k] += memo2;
				dp2[i + 1][j][k] -= dp2[i][k][j];
				dp2[i + 1][j][k] += k * dp1[i + 1][j][k];
			}
		}
	}
	mint ans1 = 0, ans2 = 0;
	rep(i, m) rep(j, m)ans1 += dp1[n - 2][i][j];
	rep(i, m) rep(j, m)ans2 += dp2[n - 2][i][j];
	cout << ans1.val() << " " << ans2.val() << endl;
	return 0;
}
0