結果

問題 No.2162 Copy and Paste 2
ユーザー miscalcmiscalc
提出日時 2021-08-26 04:36:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 872 bytes
コンパイル時間 2,810 ms
コンパイル使用メモリ 219,920 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2024-04-24 12:55:53
合計ジャッジ時間 11,667 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/string>
using namespace atcoder;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S;
  cin >> S;
  int N = S.size();

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

  vector<int> dp(N, 0);
  vector<int> dp2(N);
  for (int j = 2; j < N / 2 + 1; j++)
  {
    for (int i = j - 1; i < N; i++)
    {
      dp2[i] = dp[j - 1] - 1;
    }

    for (int i = j - 1; i < N - 1; i++)
    {
      if (Z[i + 1] >= j)
        dp2[i + j] = max(dp2[i + j], dp2[i] + j - 1);
      dp2[i + 1] = max(dp2[i + 1], dp2[i]);

      dp[i] = max(dp[i], dp2[i]);
    }
    dp[N - 1] = max(dp[N - 1], dp2[N - 1]);
  }

  int ans = N - dp[N - 1];
  cout << ans << '\n';
}
0