結果

問題 No.996 Phnom Penh
ユーザー Mayimg
提出日時 2020-02-22 19:08:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,488 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 197,296 KB
最終ジャッジ日時 2025-01-09 01:53:28
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  long long ans = 0;
  string t;
  int n = (int) s.size();
  for (int i = 0; i < n; i++) {
    if (s.substr(i, 5) == "phnom") {
      t += "penh";
      i += 4;
      ans++;
    } else {
      t += s[i];
    }
  }
  s = t;
  //cerr << s << endl;
  n = (int) s.size();
  bool found = false;
  t = "";
  for (int i = 0; i < n; i++) {
    if (s[i] == 'e' || s[i] == 'h') {
      found = true;
    }
    if (s[i] == 'e') t += 'h'; 
    else if (s[i] != 'h') t += s[i];
  }
  s = t;
  //cerr << s << endl;
  if (found) ans++;
  n = (int) s.size();
  int cnt = 0;
  int phn = false;
  vector<int> v;
  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) v.push_back(cnt);
      phn = false;
      cnt = 0;
    }
  }
  if (cnt > 0) v.push_back(cnt);
  // for (int i : v) cerr << i << " ";
  // cerr << endl;
  // cerr << ans << endl;
  if (v.empty()) {
    int mx = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'e') mx = max(2, mx);
      if (s[i] == 'h') mx = max(1, mx);
    }
    ans += mx;
  } else {
    int mx = 0;
    for (int i : v) {
      ans += i;
      mx = max(i, mx);
    }
    ans += mx + 1;
  }
  cout << ans << endl;
  return 0;
}
0