結果

問題 No.996 Phnom Penh
ユーザー MayimgMayimg
提出日時 2020-02-21 23:07:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,135 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 205,916 KB
実行使用メモリ 6,508 KB
最終ジャッジ日時 2024-04-17 09:12:45
合計ジャッジ時間 3,249 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<pair<string, int>> doit1 (string s) {
  vector<pair<string, int>> res;
  int cnt = 0;
  int n = (int) s.size() - 1;
  string t;
  for (int i = 0; i < n; i++) {
    if (s.substr(i, 2) == "om") {
      cnt++;
      i++;
    } else {
      if (cnt > 0) {
        res.emplace_back(t, cnt);
        t = "";
      }
      cnt = 0;
      t += s[i];
    }
  }
  if (cnt > 0) res.emplace_back(t, cnt);
  return res;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  int n = (int) s.size();
  vector<pair<string, int>> be = doit1 (s);
  vector<int> type1, type2;
  for (auto& p : be) {
    //cerr << p.first << " " << p.second << endl;
    int m = (int) p.first.size();
    if (m - 3 >= 0 && p.first.substr(m - 3) == "phn") {
      type1.push_back(p.second);
      continue;
    }
    int ecount = 0, ncount = 0, other = 0;
    int i;
    for (i = m - 1; i >= 0; i--) {
      if (s[i] == 'p') break;
      if (s[i] == 'e') ecount++;
      else if (s[i] == 'n') ncount++;
      else if (s[i] != 'h') other++;
    }
    if (i >= 0 && ecount == 1 && ncount == 1 && other == 0) {
      type2.push_back(p.second);
    }
  }
  // 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;
}
0