結果

問題 No.2129 Perfect Binary Tree...?
ユーザー kuronikuroni
提出日時 2022-11-18 22:19:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,412 bytes
コンパイル時間 4,647 ms
コンパイル使用メモリ 242,092 KB
実行使用メモリ 19,580 KB
最終ジャッジ日時 2023-10-20 07:10:02
合計ジャッジ時間 7,441 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 19 ms
4,348 KB
testcase_04 AC 21 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 18 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 20 ms
4,348 KB
testcase_20 AC 21 ms
4,348 KB
testcase_21 AC 20 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 20 ms
4,348 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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, dst = 0;
    for (int i = n - 1; i >= 1; i--) {
        mint ch = mint(2).pow(n - i) - 1;
        ans *= 2;
        (dst += ch) *= 2;
        ans += dst * (ch + 1);
    }
    string s, t; cin >> s >> t;
    string lca;
    int ls = s.size(), lt = t.size(), ll = 0;
    for (int i = 0; i < min(ls, lt); i++) {
        if (s[i] == t[i]) {
            lca += s[i];
            ll++;
        } else {
            break;
        }
    }
    vector<mint> xs, xt;
    mint tot = mint(2).pow(n) - 1;
    for (int i = ls; i > ll; i--) {
        xs.push_back(mint(2).pow(n - i + 1) - 1 - (xs.empty() ? 0 : xs.back()));
        tot -= xs.back();
    }
    for (int i = lt; i > ll; i--) {
        xt.push_back(mint(2).pow(n - i + 1) - 1 - (xt.empty() ? 0 : xt.back()));
        tot -= xt.back();
    }
    vector<mint> all = xs;
    all.push_back(tot);
    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