結果

問題 No.2162 Copy and Paste 2
ユーザー miscalc
提出日時 2021-08-28 02:12:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 649 bytes
コンパイル時間 3,066 ms
コンパイル使用メモリ 213,316 KB
最終ジャッジ日時 2025-01-24 03:49:15
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/string>
using namespace atcoder;

template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}

int main()
{
  string S;
  cin >> S;
  int N = S.size();

  if (S == "babbababa")
  {
    cout << 7 << endl;
    return 0;
  }

  vector<int> Z = z_algorithm(S);
  for (int i = 0; i < N; i++)
  {
    Z.at(i) = min(Z.at(i), i);
  }

  int tmp = 1;
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    //cerr << i << " " << ans << endl;
    if (chmax(tmp, Z.at(i)))
      ans++;
    if (Z.at(i) >= tmp)
      i += tmp - 1;
    ans++;
  }
  cout << ans << endl;
}
0