結果

問題 No.996 Phnom Penh
ユーザー MayimgMayimg
提出日時 2020-02-22 19:08:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,488 bytes
コンパイル時間 2,333 ms
コンパイル使用メモリ 199,396 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 03:00:57
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 WA -
testcase_25 AC 7 ms
6,940 KB
testcase_26 AC 6 ms
6,940 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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