結果

問題 No.996 Phnom Penh
ユーザー LayCurseLayCurse
提出日時 2020-02-21 22:03:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 3,417 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 207,740 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 07:38:05
合計ジャッジ時間 3,572 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
char S[200000+2];
int main(){
  int Lj4PdHRW, i;
  int k;
  int ok;
  long long res = 0;
  N = rd(S);
  for(Lj4PdHRW=(0);Lj4PdHRW<(2);Lj4PdHRW++){
    int i;
    k = ok = 0;
    for(i=(0);i<(N);i++){
      if(i+4 < N && S[i]=='p' && S[i+1]=='h' && S[i+2]=='n' && S[i+3]=='o' && S[i+4]=='m'){
        res++;
        S[k++] = 'p';
        S[k++] = 'e';
        S[k++] = 'n';
        S[k++] = 'h';
        ok++;
        i += 4;
        continue;
      }
      S[k++] = S[i];
    }
    N = k;
    k = 0;
    for(i=(0);i<(N);i++){
      if(S[i]=='e' || S[i]=='h'){
        k++;
      }
    }
    if(k){
      k = 0;
      for(i=(0);i<(N);i++){
        if(S[i]=='h'){
          continue;
        }
        if(S[i]=='e'){
          S[k++] = 'h';
          continue;
        }
        S[k++] = S[i];
      }
      res++;
      ok++;
    }
    N = k;
  }
  int mx = 0;
  int tmp;
  for(i=(0);i<(N);i++){
    if(S[i]=='e'){
      chmax(mx, 2);
    }
    if(S[i]=='h'){
      chmax(mx, 1);
    }
    if(i+2 < N && S[i]=='p' && S[i+1]=='h' && S[i+2]=='n'){
      tmp = 0;
      while(i+4+2*tmp < N && S[i+3+2*tmp]=='o' && S[i+4+2*tmp]=='m'){
        tmp++;
      }
      chmax(mx, tmp + 1);
      res += tmp;
    }
  }
  res += mx;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200217-1

// --- original code ---
// int N;
// char S[2d5+2];
// {
//   int k, ok;
//   ll res = 0;
//   rd(S@N);
// 
//   rep(2){
//     k = ok = 0;
//     rep(i,N){
//       if(i+4 < N && S[i]=='p' && S[i+1]=='h' && S[i+2]=='n' && S[i+3]=='o' && S[i+4]=='m'){
//         res++;
//         S[k++] = 'p';
//         S[k++] = 'e';
//         S[k++] = 'n';
//         S[k++] = 'h';
//         ok++;
//         i += 4;
//         continue;
//       }
//       S[k++] = S[i];
//     }
//     N = k;
// 
//     k = 0;
//     rep(i,N) if(S[i]=='e' || S[i]=='h') k++;
//     if(k){
//       k = 0;
//       rep(i,N){
//         if(S[i]=='h') continue;
//         if(S[i]=='e') S[k++] = 'h', continue;
//         S[k++] = S[i];
//       }
//       res++;
//       ok++;
//     }
//     N = k;
//   }
// 
//   int mx = 0, tmp;
//   rep(i,N){
//     if(S[i]=='e') mx >?= 2;
//     if(S[i]=='h') mx >?= 1;
//     if(i+2 < N && S[i]=='p' && S[i+1]=='h' && S[i+2]=='n'){
//       tmp = 0;
//       while(i+4+2tmp < N && S[i+3+2tmp]=='o' && S[i+4+2tmp]=='m') tmp++;
//       mx >?= tmp + 1;
//       res += tmp;
//     }
//   }
//   res += mx;
// 
//   wt(res);
// }
0