結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
15,136 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 10 ms
8,064 KB
testcase_03 AC 10 ms
7,904 KB
testcase_04 AC 9 ms
8,064 KB
testcase_05 AC 9 ms
8,064 KB
testcase_06 AC 11 ms
8,064 KB
testcase_07 AC 10 ms
8,008 KB
testcase_08 AC 11 ms
7,936 KB
testcase_09 WA -
testcase_10 AC 10 ms
7,936 KB
testcase_11 AC 9 ms
7,936 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1,188 ms
8,576 KB
testcase_14 AC 29 ms
7,936 KB
testcase_15 AC 1,403 ms
8,704 KB
testcase_16 AC 67 ms
9,972 KB
testcase_17 AC 85 ms
10,088 KB
testcase_18 AC 70 ms
9,832 KB
testcase_19 AC 63 ms
10,116 KB
testcase_20 AC 35 ms
9,984 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() && s[0] == '>') {
    			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