結果

問題 No.2129 Perfect Binary Tree...?
ユーザー kuronikuroni
提出日時 2022-11-19 05:54:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 3,000 ms
コード長 1,267 bytes
コンパイル時間 4,035 ms
コンパイル使用メモリ 241,552 KB
実行使用メモリ 19,544 KB
最終ジャッジ日時 2023-10-20 13:06:02
合計ジャッジ時間 7,295 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 31 ms
4,348 KB
testcase_04 AC 34 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 47 ms
5,516 KB
testcase_07 AC 40 ms
4,604 KB
testcase_08 AC 84 ms
10,424 KB
testcase_09 AC 91 ms
11,316 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 24 ms
5,024 KB
testcase_12 AC 87 ms
10,244 KB
testcase_13 AC 142 ms
19,544 KB
testcase_14 AC 87 ms
11,516 KB
testcase_15 AC 83 ms
10,472 KB
testcase_16 AC 135 ms
16,920 KB
testcase_17 AC 30 ms
4,348 KB
testcase_18 AC 33 ms
4,348 KB
testcase_19 AC 33 ms
4,348 KB
testcase_20 AC 33 ms
4,348 KB
testcase_21 AC 32 ms
4,348 KB
testcase_22 AC 32 ms
4,348 KB
testcase_23 AC 130 ms
16,840 KB
testcase_24 AC 133 ms
17,176 KB
testcase_25 AC 59 ms
7,492 KB
testcase_26 AC 31 ms
4,348 KB
testcase_27 AC 36 ms
6,928 KB
testcase_28 AC 86 ms
11,064 KB
testcase_29 AC 93 ms
12,024 KB
testcase_30 AC 145 ms
19,544 KB
testcase_31 AC 89 ms
11,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    mint ans = 0, tot = mint(2).pow(n) - 1;
    for (int i = 1; i <= n; i++) {
        mint sub = mint(2).pow(i) - 1;
        ans += mint(2).pow(n - i) * sub * (tot - sub);
    }
    string s, t; cin >> s >> t;
    int ls = s.size(), lt = t.size(), ll = 0;
    for (; ll < min(ls, lt); ll++) {
        if (s[ll] != t[ll]) {
            break;
        }
    }
    vector<mint> xs, xt;
    mint ss = 0, st = 0;
    for (int i = ls; i > ll; i--) {
        xs.push_back(mint(2).pow(n - i + 1) - 1 - ss);
        ss += xs.back();
    }
    for (int i = lt; i > ll; i--) {
        xt.push_back(mint(2).pow(n - i + 1) - 1 - st);
        st += xt.back();
    }
    vector<mint> all = xs;
    all.push_back(tot - ss - st);
    all.insert(all.end(), xt.rbegin(), xt.rend());
    vector<mint> rev = all; reverse(rev.begin(), rev.end());
    int sz = all.size();
    vector<mint> res = convolution(all, rev);
    for (int i = 0; i < res.size(); i++) {
        int dif = i - sz + 1;
        ans -= max(0, 2 * dif - sz) * res[i];
    }
    cout << ans.val();
}
0