結果

問題 No.2162 Copy and Paste 2
ユーザー miscalcmiscalc
提出日時 2021-08-28 02:49:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,054 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 209,012 KB
実行使用メモリ 24,960 KB
最終ジャッジ日時 2024-04-24 13:00:46
合計ジャッジ時間 27,257 ms
ジャッジサーバーID
(参考情報)
judge3 / 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 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 84 ms
15,360 KB
testcase_07 AC 90 ms
14,976 KB
testcase_08 AC 442 ms
22,868 KB
testcase_09 AC 305 ms
15,360 KB
testcase_10 AC 344 ms
14,976 KB
testcase_11 AC 500 ms
19,712 KB
testcase_12 AC 523 ms
17,152 KB
testcase_13 AC 878 ms
22,968 KB
testcase_14 AC 372 ms
16,384 KB
testcase_15 AC 432 ms
16,128 KB
testcase_16 AC 418 ms
16,256 KB
testcase_17 AC 1,400 ms
22,924 KB
testcase_18 AC 4,621 ms
24,960 KB
testcase_19 AC 2,688 ms
23,508 KB
testcase_20 AC 1,755 ms
23,480 KB
testcase_21 AC 617 ms
23,080 KB
testcase_22 AC 593 ms
23,020 KB
testcase_23 AC 28 ms
12,928 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/lazysegtree>
using namespace atcoder;

int mymax(int a, int b)
{
  return max(a, b);
}

int e()
{
  return 0;
}

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

  vector<int> Z(N);
  for (int i = 0; i < N; i++)
  {
    int j = 0;
    while (j < i && i + j < N && S[j] == S[i + j])
    {
      j++;
    }
    Z[i] = j;
    //cerr << i << " " << j << endl;
  }

  vector<vector<int>> invZ(N);
  set<int> st;
  for (int i = 0; i < N; i++)
  {
    if (Z.at(i) >= 2)
    {
      invZ.at(Z.at(i)).push_back(i);
      st.emplace(i);
    }
  }
  st.emplace(N + 1);

  lazy_segtree<int, mymax, e, int, mymax, mymax, e> dp(N + 1);
  for (int j = 2; j < N; j++)
  {
    int cnt = dp.get(j) + j - 2;
    int i = *st.begin() + j;
    while (i < N + 1)
    {
      dp.apply(i, N + 1, cnt);

      cnt += j - 1;
      i = *st.lower_bound(i) + j;
    }

    for (auto ii : invZ.at(j))
    {
      st.erase(ii);
    }
  }

  int ans = N - dp.get(N);
  cout << ans << endl;
}
0