結果

問題 No.3757 Happy End
コンテスト
ユーザー tnakao0123
提出日時 2026-10-10 18:12:13
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
+ 11µs
コード長 649 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 161 ms
コンパイル使用メモリ 53,420 KB
実行使用メモリ 9,844 KB
最終ジャッジ日時 2026-10-10 18:12:19
合計ジャッジ時間 2,959 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3757.cc:  No.3757 Happy End - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 300000;
const int L = 5;
const char p[] = "HAPPY";

/* typedef */

/* global variables */

char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d%s", &n, s);

  int sum = 0;
  for (int i = 0; i < L; i++)
    if (s[n - L + i] != p[i]) sum++;
  copy(p, p + L, s + (n - L));
  
  for (int i = 0; i < n - L;) {
    if (! strncmp(s + i, p, L)) s[i + L - 1] = 'Z', sum++, i += L;
    else i++;
  }

  printf("%d\n", sum);

  return 0;
}
0