結果
| 問題 |
No.2162 Copy and Paste 2
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-12-13 23:11:10 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 7,000 ms |
| コード長 | 1,298 bytes |
| コンパイル時間 | 6,399 ms |
| コンパイル使用メモリ | 150,024 KB |
| 最終ジャッジ日時 | 2025-02-09 11:09:23 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;
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(){
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;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia