結果

問題 No.996 Phnom Penh
ユーザー plin92793134plin92793134
提出日時 2020-02-23 15:06:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,018 bytes
コンパイル時間 1,098 ms
コンパイル使用メモリ 103,652 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 08:44:04
合計ジャッジ時間 1,873 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 10 ms
5,376 KB
testcase_27 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,ns;cin>>s;
  string phn="phn",penh="penh",om="om";
  ll res=0;
  rep(i,s.length()){
    if(s[i]=='e')res=2;
    if(s[i]=='h')chmax(res,1ll);
  }
  auto cntom=[&](ll id,ll f){
    ll l=s.length();
    ll nid=id;
    ll tot=0;
    while(nid<l){
      if(nid+1<l&&s.substr(nid,2)==om){
        tot++;
        nid+=2;
      }
      else if(f){
        if(s[nid]=='h'){
          nid++;
          continue;
        }
        if(tot>0 && s[nid]=='e'){
          nid++;
          continue;
        }
        break;
      }
      else{

        if(tot>0 && s[nid]=='h'){
          nid++;
          continue;
        }
        if(tot>1 && s[nid]=='e'){
          nid++;
          continue;
        }
        break;
      }
    }
    return tot;
  };
  ll tres=0;
  auto op12=[&]{
    ns="";
    bool f=0;
    ll l=s.length();
    rep(i,l){
      if(i+2<l&&s.substr(i,3)==phn){
        ll tc=cntom(i+3,0);
        chmax(res,tc+1);
        tres+=tc;
      }

      if(i+3<l&&s.substr(i,4)==penh){
        ll tc=cntom(i+4,1);

        chmax(res,tc+2);
        tres+=tc;
      }
    }
    return f;
  };
  op12();
  cout<<res+tres<<endl;

  return 0;

}
0