結果

問題 No.2162 Copy and Paste 2
ユーザー miscalcmiscalc
提出日時 2021-08-24 23:37:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,891 ms / 7,000 ms
コード長 963 bytes
コンパイル時間 3,187 ms
コンパイル使用メモリ 230,456 KB
実行使用メモリ 25,392 KB
最終ジャッジ日時 2023-08-06 18:06:41
合計ジャッジ時間 25,070 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 94 ms
15,168 KB
testcase_07 AC 100 ms
14,720 KB
testcase_08 AC 501 ms
22,704 KB
testcase_09 AC 321 ms
15,048 KB
testcase_10 AC 368 ms
14,812 KB
testcase_11 AC 563 ms
19,672 KB
testcase_12 AC 573 ms
17,020 KB
testcase_13 AC 971 ms
22,844 KB
testcase_14 AC 402 ms
16,344 KB
testcase_15 AC 469 ms
16,108 KB
testcase_16 AC 451 ms
16,108 KB
testcase_17 AC 1,330 ms
22,696 KB
testcase_18 AC 1,627 ms
24,888 KB
testcase_19 AC 1,410 ms
23,296 KB
testcase_20 AC 1,374 ms
22,968 KB
testcase_21 AC 720 ms
22,708 KB
testcase_22 AC 675 ms
22,816 KB
testcase_23 AC 31 ms
12,592 KB
testcase_24 AC 1,862 ms
25,392 KB
testcase_25 AC 1,891 ms
25,152 KB
testcase_26 AC 1,738 ms
25,064 KB
testcase_27 AC 1,865 ms
25,152 KB
testcase_28 AC 1,403 ms
19,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/string>
#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 = z_algorithm(S);
  for (int i = 0; i < N; i++)
  {
    Z.at(i) = min(Z.at(i), i);
  }

  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