結果
問題 |
No.2162 Copy and Paste 2
|
ユーザー |
![]() |
提出日時 | 2021-08-28 02:49:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,054 bytes |
コンパイル時間 | 2,395 ms |
コンパイル使用メモリ | 208,720 KB |
最終ジャッジ日時 | 2025-01-24 03:51:50 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 TLE * 3 |
ソースコード
#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; }