結果

問題 No.2219 Re:010
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-02-19 02:07:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,248 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 190,980 KB
実行使用メモリ 4,448 KB
最終ジャッジ日時 2023-09-27 13:11:51
合計ジャッジ時間 4,584 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 78 ms
4,376 KB
testcase_04 AC 11 ms
4,376 KB
testcase_05 AC 61 ms
4,376 KB
testcase_06 AC 18 ms
4,380 KB
testcase_07 AC 38 ms
4,376 KB
testcase_08 AC 71 ms
4,380 KB
testcase_09 AC 70 ms
4,380 KB
testcase_10 AC 52 ms
4,380 KB
testcase_11 AC 44 ms
4,384 KB
testcase_12 AC 45 ms
4,384 KB
testcase_13 AC 87 ms
4,380 KB
testcase_14 AC 89 ms
4,376 KB
testcase_15 AC 92 ms
4,380 KB
testcase_16 AC 90 ms
4,376 KB
testcase_17 AC 90 ms
4,376 KB
testcase_18 AC 84 ms
4,380 KB
testcase_19 AC 32 ms
4,380 KB
testcase_20 AC 117 ms
4,448 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:39:18: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   39 |         for(auto [u, v] : edges[s[i]])
      |                  ^
main.cpp:44:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   44 |     for(auto [s, i] : dp) {
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 2e5 + 10, P = 998244353;

char s[N];

int p2[N];

int cnt[256];

map<string, int> dp;

vector<pair<string, string> > edges[256];

int main() {
    cin >> s;
    int n = strlen(s);
    for(int i = 0; i < n; i ++)
        cnt[s[i]] ++;
    
    p2[0] = 1;
    for(int i = 1; i <= cnt['?']; i ++)
        p2[i] = p2[i - 1] * 2 % P;
    
    for(string i : {"0", "?"}) {
        edges[i[0]].push_back({"", i});
        for(string j : {"1", "?"}) {
            edges[j[0]].push_back({i, i + j});
            for(string k : {"0", "?"})
                edges[k[0]].push_back({i + j, i + j + k});
        }
    }
    for(char i : {'0', '1', '?'})
        sort(edges[i].begin(), edges[i].end(), [](pair<string, string> &a, pair<string, string> &b) {return a.second.length() > b.second.length();});
    
    dp[""] = 1;
    for(int i = 0; i < n; i ++) {
        for(auto [u, v] : edges[s[i]])
            dp[v] = (dp[v] + dp[u]) % P;
    }

    int ans = 0;
    for(auto [s, i] : dp) {
        if(s.length() < 3) continue;
        int c2 = 0;
        for(char c : s)
            c2 += (c == '?');
        ans = (ans + (i64)p2[cnt['?'] - c2] * i) % P;
    }
    cout << ans;
}
0