結果
問題 | No.2373 wa, wo, n |
ユーザー |
![]() |
提出日時 | 2023-06-23 18:52:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 991 bytes |
コンパイル時間 | 2,317 ms |
コンパイル使用メモリ | 199,680 KB |
最終ジャッジ日時 | 2025-02-15 00:33:25 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N; cin >> N; string S; cin >> S; auto match = [&](string s, string p) -> bool { assert(s.size() == p.size()); for (int i = 0; i < (int)s.size(); i++) { if (s[i] == p[i] || s[i] == '?') { continue; } return false; } return true; }; vector<string> patterns = {"wa", "wo", "n"}; // dp[i] := S[0,i) が wawon 文字列であるか否か vector<bool> dp(N + 1); dp[0] = true; for (int i = 0; i < N; i++) { if (not dp[i]) { continue; } for (auto p : patterns) { int n = p.size(); if (i + n <= N && match(S.substr(i, n), p)) { dp[i + n] = true; } } } string ans = (dp[N] ? "Yes" : "No"); cout << ans << '\n'; return 0; }