結果

問題 No.996 Phnom Penh
ユーザー beetbeet
提出日時 2020-02-21 22:10:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 2,014 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 208,960 KB
実行使用メモリ 28,180 KB
最終ジャッジ日時 2024-04-17 07:40:19
合計ジャッジ時間 3,469 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_07 AC 1 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 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 36 ms
21,776 KB
testcase_14 AC 36 ms
21,652 KB
testcase_15 AC 35 ms
21,652 KB
testcase_16 AC 36 ms
21,784 KB
testcase_17 AC 37 ms
21,780 KB
testcase_18 AC 2 ms
5,376 KB
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 AC 2 ms
5,376 KB
testcase_24 AC 10 ms
5,376 KB
testcase_25 AC 49 ms
28,176 KB
testcase_26 AC 35 ms
20,244 KB
testcase_27 AC 49 ms
28,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE

deque<char> op(deque<char> dd){
  deque<char> rs;
  for(char &c:dd){
    if(c=='h') continue;
    rs.emplace_back(c);
  }
  for(char &c:rs){
    if(c=='e') c='h';
  }
  return rs;
}

signed main(){
  string s;
  cin>>s;

  vector<deque<char>> vs;
  for(char c:s){
    if(vs.empty()||c=='p') vs.emplace_back();
    vs.back().emplace_back(c);
  }

  Int ans=0;
  deque<char> dc;
  for(char c:"phnom"s) dc.emplace_back(c);

  Int max_num=0;
  for(auto dd:vs){
    //    cout<<string(dd.begin(),dd.end())<<endl;

    Int ex_e=1;
    Int ex_h=1;

    Int num=0;

    while(1){
      Int flg=0;
      if(dd.size()>=5){
        flg=1;
        for(Int i=0;i<5;i++)
          flg&=dd[i]==dc[i];
      }
      if(!flg){
        if(count(dd.begin(),dd.end(),'h')||count(dd.begin(),dd.end(),'e')){
          dd=op(dd);
          num++;
        }else{
          break;
        }
      }else{
        break;
      }
    }

    while(1){
      Int change=0;
      Int flg=0;
      if(dd.size()>=5){
        flg=1;
        for(Int i=0;i<5;i++)
          flg&=dd[i]==dc[i];
      }
      if(flg){
        dd.pop_front();
        dd.pop_front();
        dd.pop_front();
        dd.pop_front();
        dd.pop_front();
        change++;
      }else{
        while(count(dd.begin(),dd.end(),'h')||count(dd.begin(),dd.end(),'e')){
          dd=op(dd);
          num++;
        }
        break;
      }

      if(ex_h||ex_e){
        dd=op(dd);
        ex_h=count(dd.begin(),dd.end(),'h');
        ex_e=count(dd.begin(),dd.end(),'e');
      }

      dd.emplace_front('n');
      dd.emplace_front('h');
      dd.emplace_front('p');
      num++;

      if(!change) break;
      ans+=change;
    }
    chmax(max_num,num);
  }
  // cout<<max_num<<endl;
  cout<<ans+max_num<<endl;
  return 0;
}
0