結果

問題 No.2794 I Love EDPC-T
ユーザー 👑 箱星箱星
提出日時 2023-02-04 02:07:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,396 bytes
コンパイル時間 3,600 ms
コンパイル使用メモリ 243,740 KB
実行使用メモリ 22,424 KB
最終ジャッジ日時 2024-05-30 16:24:48
合計ジャッジ時間 8,419 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
14,876 KB
testcase_01 AC 10 ms
8,044 KB
testcase_02 AC 8 ms
7,936 KB
testcase_03 AC 10 ms
7,932 KB
testcase_04 AC 9 ms
8,064 KB
testcase_05 AC 9 ms
8,032 KB
testcase_06 AC 95 ms
8,064 KB
testcase_07 AC 161 ms
8,192 KB
testcase_08 AC 229 ms
8,296 KB
testcase_09 AC 10 ms
7,980 KB
testcase_10 AC 10 ms
7,936 KB
testcase_11 AC 10 ms
7,936 KB
testcase_12 AC 9 ms
7,936 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/convolution>
#include <atcoder/modint>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
    const int fac_size = 600000;
    vector<mint> fac(fac_size);
    vector<mint> inv_fac(fac_size);
    fac[0] = 1;
    inv_fac[0] = 1;
    for (int i = 1; i < fac_size; i++) {
    	fac[i] = fac[i - 1] * i;
    }
    inv_fac[fac_size - 1] = 1 / fac[fac_size - 1];
    for (int i = fac_size - 2; i >= 1; i--) {
    	inv_fac[i] = inv_fac[i + 1] * (i + 1);
    }
    
    int n;
    string s;
    cin >> n;
    cin >> s;
    int p = 0;
    for (int i = 0; i < n - 1; i++) {
    	if (s[i] == '<') {
    		p++;
    	}
    }
    if (p == 0) {
    	cout << 0 << endl;
    	return 0;
    }
    p %= 2;
    vector<vector<mint>> dp(n, vector<mint>(2));
    dp[0][0] = 1;
    for (int i = 0; i < n - 1; i++) {
    	vector<vector<mint>> newdp(n, vector<mint>(2));
    	for (int j = 0; j <= i; j++) {
    		if (s[i] == '>') {
    			newdp[j][0] += dp[j][0] + dp[j][1];
    		}
    		newdp[j + 1][1] += dp[j][0]; 
    	}
    	dp = newdp;
    }
    mint ans = 0;
    for (int i = 0; i < n; i++) {
    	mint num = fac[2 * (n - i)] * inv_fac[n - i] * inv_fac[n - i] / (n - i + 1) * (dp[i][0] + dp[i][1]);
    	if (i % 2 == p) {
    		ans += num;
    	} else {
    		ans -= num;
    	}
    }
    cout << ans.val() << endl;
    return 0;
}
0