結果
| 問題 |
No.2162 Copy and Paste 2
|
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2021-12-22 07:15:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,669 ms / 7,000 ms |
| コード長 | 1,120 bytes |
| コンパイル時間 | 1,935 ms |
| コンパイル使用メモリ | 105,632 KB |
| 最終ジャッジ日時 | 2025-01-27 05:08:43 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
// https://yukicoder.me/submissions/692208
// 上をベースに書き換え
#include <atcoder/string>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace atcoder;
using namespace std;
int main(void) {
string s;
cin >> s;
const int n = s.size();
const vector<int> z = z_algorithm(s);
vector<int> ord;
set<int> st;
for (int i = 1; i < n; ++i) {
if (z[i] >= 1) {
ord.push_back(i);
st.emplace(i);
}
}
st.emplace(n);
sort(ord.begin(), ord.end(), [&](int a, int b) { return z[a] < z[b]; });
vector<int> dp(n + 1, 0);
for (int i = 1, x = 0; i < n; ++i) {
int d = dp[i];
dp[i + 1] = max(dp[i + 1], d);
d -= 1;
int pos = *st.lower_bound(i);
while (pos < n) {
d += i - 1;
dp[pos + i] = max(dp[pos + i], d);
pos = *st.lower_bound(pos + i);
}
for (; x < (int)ord.size() && z[ord[x]] == i; ++x) {
st.erase(ord[x]);
}
}
int ans = n - dp[n];
cout << ans << endl;
}
akakimidori