結果
| 問題 |
No.2162 Copy and Paste 2
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2024-04-26 02:04:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 139 ms / 7,000 ms |
| コード長 | 1,082 bytes |
| コンパイル時間 | 2,201 ms |
| コンパイル使用メモリ | 112,552 KB |
| 最終ジャッジ日時 | 2025-02-21 09:04:01 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
#include <atcoder/string>
#include <atcoder/segtree>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using Modint = atcoder::static_modint<998244353>;
namespace RMQ{
using S = int;
S op(S l, S r){ return max(l, r); }
S e(){ return -1; }
using Segtree = atcoder::segtree<S, op, e>;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string S; cin >> S;
auto Z = atcoder::z_algorithm(S);
int n = S.size();
RMQ::Segtree segtree(atcoder::z_algorithm(S));
vector<int> dp(n+1);
rep(i,n+1) dp[i] = i;
for(int x=1; x<=n; x++){
dp[x] = min(dp[x], dp[x-1] + 1);
int p = x, t = dp[x] + 1;
while(p < n){
int nx = segtree.max_right(p, [x](int v){ return v<x; });
if(nx >= n) break;
t += nx - p + 1;
p = nx + x;
dp[p] = min(dp[p], t);
}
}
cout << dp[n] << '\n';
return 0;
}
Nachia