結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-21 22:44:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,399 bytes |
| コンパイル時間 | 2,736 ms |
| コンパイル使用メモリ | 201,028 KB |
| 最終ジャッジ日時 | 2025-01-09 01:40:19 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 15 TLE * 1 |
コンパイルメッセージ
main.cpp: In function ‘std::vector<int> find_type2(std::string)’:
main.cpp:51:7: warning: ‘j’ may be used uninitialized [-Wmaybe-uninitialized]
51 | if (j < 0) i = j + 1;
| ^~
main.cpp:44:11: note: ‘j’ was declared here
44 | int j;
| ^
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> find_type1 (string s) {
int n = (int) s.size();
int cnt = 0;
int phn = false;
vector<int> res;
for (int i = 0; i < n; i++) {
if (s.substr(i, 3) == "phn") {
cnt = 0;
phn = true;
i += 2;
continue;
}
if (s.substr(i, 2) == "om" && phn) {
cnt++;
i += 1;
} else {
if (cnt > 0) res.push_back(cnt);
phn = false;
cnt = 0;
}
}
if (cnt > 0) res.push_back(cnt);
return res;
}
vector<int> find_type2 (string s) {
int n = (int) s.size();
int cnt = 0;
vector<int> res;
for (int i = n - 2; i >= 0; i--) {
if (s.substr(i, 2) == "om") {
cnt++;
i--;
} else {
i++;
if (s[i] != 'e' && s[i] != 'h' && s[i] != 'n') {
i--;
cnt = 0;
continue;
}
i--;
int j;
int ecount = 0, ncount = 0, others = 0;
for (int j = i + 1; j >= 0 && s[j] != 'p'; j--) {
if (s[j] == 'e') ecount++;
else if (s[j] == 'n') ncount++;
else if (s[j] != 'h') others++;
}
if (j < 0) i = j + 1;
else if (others == 0 && ecount == 1 && ncount == 1) {
if (cnt > 0) res.push_back(cnt);
}
cnt = 0;
}
}
return res;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
string s;
cin >> s;
int n = (int) s.size();
//phnomom...
auto type1 = find_type1(s);
//penomom..
auto type2 = find_type2(s);
// for (int i : type1) cerr << i << " ";
// cerr << endl;
// for (int i : type2) cerr << i << " ";
// cerr << endl;
long long ans = 0;
if (type1.empty() && type2.empty()) {
int ecount = 0, hcount = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'e') ecount++;
if (s[i] == 'h') hcount++;
}
if (hcount) ans = 1;
if (ecount) ans = 2;
} else if (type2.empty()) {
sort(type1.begin(), type1.begin());
ans += type1.back() + 1;
for (int i : type1) ans += i;
} else if (type1.empty()) {
sort(type2.begin(), type2.begin());
ans += type2.back() + 1;
for (int i : type2) ans += i;
ans += 1;
} else {
for (int i : type1) {
ans++;
if (i > 0) type2.push_back(i - 1);
}
sort(type2.begin(), type2.begin());
ans += type2.back() + 1;
for (int i : type2) ans += i;
ans += 1;
}
cout << ans << endl;
return 0;
}