結果

問題 No.2129 Perfect Binary Tree...?
ユーザー kuronikuroni
提出日時 2022-11-19 03:46:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,326 bytes
コンパイル時間 4,226 ms
コンパイル使用メモリ 241,756 KB
実行使用メモリ 19,568 KB
最終ジャッジ日時 2023-10-20 11:43:55
合計ジャッジ時間 7,455 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 33 ms
4,348 KB
testcase_04 AC 34 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 30 ms
4,348 KB
testcase_18 AC 34 ms
4,348 KB
testcase_19 AC 34 ms
4,348 KB
testcase_20 AC 35 ms
4,348 KB
testcase_21 AC 34 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 34 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, 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 (int i = 0; i < min(ls, lt); i++) {
        if (s[i] == t[i]) {
            ll++;
        } else {
            break;
        }
    }
    vector<mint> xs, xt;
    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