結果
| 問題 |
No.2373 wa, wo, n
|
| コンテスト | |
| ユーザー |
poyon
|
| 提出日時 | 2023-06-24 00:37:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 2,000 ms |
| コード長 | 1,427 bytes |
| コンパイル時間 | 2,048 ms |
| コンパイル使用メモリ | 198,648 KB |
| 最終ジャッジ日時 | 2025-02-15 01:48:10 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 39 |
ソースコード
// 別解(貪欲法)
// (1) w? -> wa
// (2) ?a -> wa
// (3) ?o -> wo
// (4) ? -> n
#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;
string T = "waon?";
for (auto s : S) {
if (T.find(s) == string::npos) {
cout << "No" << '\n';
return 0;
}
}
for (int i = 0; i + 1 < N; i++) {
if (S[i] == 'w' && S[i + 1] == '?') {
S[i + 1] = 'a';
}
if (S[i] == '?' && (S[i + 1] == 'a' || S[i + 1] == 'o')) {
S[i] = 'w';
}
}
for (auto& s : S) {
if (s == '?') { s = 'n'; }
}
vector<string> patterns = {"wa", "wo", "n"};
auto is_wawon = [&](string S) -> bool {
int i = 0;
while (true) {
if (i == N) { return true; }
bool found = false;
for (auto p : patterns) {
int n = p.size();
if (i + n <= N && S.substr(i, n) == p) {
i += n;
found = true;
break;
}
}
if (not found) { break; }
}
return false;
};
bool ok = is_wawon(S);
string ans = (ok ? "Yes" : "No");
cout << ans << '\n';
return 0;
}
poyon