結果
| 問題 |
No.2219 Re:010
|
| コンテスト | |
| ユーザー |
鴨志田卓
|
| 提出日時 | 2023-02-19 02:07:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 125 ms / 2,000 ms |
| コード長 | 1,248 bytes |
| コンパイル時間 | 3,073 ms |
| コンパイル使用メモリ | 195,920 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:19:49 |
| 合計ジャッジ時間 | 5,097 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:18: warning: 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: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
44 | for(auto [s, i] : dp) {
| ^
ソースコード
#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;
}
鴨志田卓