結果

問題 No.1492 01文字列と転倒
ユーザー startcppstartcpp
提出日時 2021-04-30 23:06:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 4,000 ms
コード長 1,102 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 67,924 KB
実行使用メモリ 7,248 KB
最終ジャッジ日時 2023-09-26 07:47:24
合計ジャッジ時間 2,850 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 120 ms
7,156 KB
testcase_03 AC 111 ms
7,004 KB
testcase_04 AC 103 ms
6,912 KB
testcase_05 AC 88 ms
6,664 KB
testcase_06 AC 92 ms
6,752 KB
testcase_07 AC 99 ms
7,108 KB
testcase_08 AC 120 ms
7,248 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 91 ms
7,000 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,384 KB
testcase_17 AC 88 ms
6,752 KB
testcase_18 AC 5 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 74 ms
6,436 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m;
int dp[2][101][4951];

int snuke(int n, int i) {
	return min(i, 2 * n - i);
}

//途中は良いカッコ列じゃなくて良いので、転倒数が結構増えることに注意
int rng(int n, int i) {
	return min(((i + 1) / 2) * (i / 2), n * (n - 1) / 2);
}

signed main() {
	int i, j, k;
	
	cin >> n >> m;
	
	dp[0][0][0] = 1;
	rep(i, 2 * n) {
		int snu1 = snuke(n, i);
		int rin1 = rng(n, i);
		int snu2 = snuke(n, i + 1);
		int rin2 = rng(n, i + 1);
		
		for (j = 0; j <= snu1; j++) {
			if ((i - j) & 1) continue;
			int one = (i - j) / 2;
			for (k = 0; k <= rin1; k++) {
				if (j + 1 <= snu2) {
					(dp[1][j + 1][k + one] += dp[0][j][k]) %= m;
				}
				if (j - 1 >= 0) {
					(dp[1][j - 1][k] += dp[0][j][k]) %= m;
				}
			}
		}
		rep(j, snu2 + 1) rep(k, rin2 + 1) dp[0][j][k] = dp[1][j][k];
		rep(j, snu2 + 1) rep(k, rin2 + 1) dp[1][j][k] = 0;
	}
	
	rep(i, n * n + 1) {
		if (i > rng(n, 2 * n)) { cout << 0 << endl; continue; }
		cout << dp[0][0][i] << endl;
	}
	return 0;
}
0