結果

問題 No.2794 I Love EDPC-T
ユーザー 👑 箱星箱星
提出日時 2023-02-03 08:35:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,840 bytes
コンパイル時間 4,149 ms
コンパイル使用メモリ 244,612 KB
実行使用メモリ 16,188 KB
最終ジャッジ日時 2024-05-30 16:24:30
合計ジャッジ時間 12,249 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
15,136 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 11 ms
8,064 KB
testcase_05 WA -
testcase_06 AC 11 ms
8,040 KB
testcase_07 AC 13 ms
8,064 KB
testcase_08 AC 12 ms
8,012 KB
testcase_09 WA -
testcase_10 AC 11 ms
7,936 KB
testcase_11 AC 11 ms
7,936 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 WA -
testcase_14 AC 33 ms
7,936 KB
testcase_15 AC 1,579 ms
8,576 KB
testcase_16 AC 74 ms
9,968 KB
testcase_17 AC 96 ms
9,960 KB
testcase_18 AC 79 ms
9,956 KB
testcase_19 AC 71 ms
9,860 KB
testcase_20 AC 41 ms
9,856 KB
testcase_21 TLE -
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() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    
    for (int i = 0; i < n - 2; i++) {
    	if (s[i] == '<' && s[i + 1] == '<') {
    		cout << 0 << endl;
    		return 0;
    	}
    }
    
    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);
    }
    
    vector<int> v;
    int streak = 0;
    for (int i = 0; i < n - 1; i++) {
    	if (s[i] == '>') {
    		streak++;
    	} else if (streak > 0) {
    		if (v.empty()) {
    			v.push_back(streak);
    		} else if (streak >= 2) {
    			v.push_back(streak - 1);
    		}
    		streak = 0;
    	}
    }
    if (streak > 0) {
    	v.push_back(streak);
    }
    if (streak == n - 1) {
    	cout << 0 << endl;
    	return 0;
    }
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
    	if (s[i] == '<') cnt++;
    }
    vector<mint> f(cnt + 1);
    f[cnt] = 1;
    for (auto e : v) {
    	vector<mint> g;
    	int i = 0;
    	while (true) {
    		if (e - i < i) break;
    		g.push_back(fac[e - i] * inv_fac[i] * inv_fac[e - 2 * i]);
    		i++;
    	}
    	f = convolution(f, g);
    }
    mint ans = 0;
    for (int i = cnt; i < n - 1; i++) {
    	if (i >= f.size()) break;
    	mint y = f[i] * (fac[2 * n - 2 * i] * inv_fac[n - i] * inv_fac[n - i]) / (n - i + 1);
    	if (i % 2 == cnt % 2) {
    		ans += y;
    	} else {
    		ans -= y;
    	}
    }
    cout << ans.val() << endl;
    return 0;
}
0