记录编号 597313 评测结果 AAAAAAAAAA
题目名称 二分的代价 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 4.492 s
提交时间 2024-11-26 15:29:17 内存使用 54.69 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,ll>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e5+10,M = 210;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}

int n;
int a[N];
char c[N];
int f[N][M],pre[N][10];

int main(){
	freopen("changgao_cost.in","r",stdin);
	freopen("changgao_cost.out","w",stdout);
	scanf("%s",c + 1);
	n = strlen(c + 1);
	for(int i = 1;i <= n;i++)a[i] = c[i] - '0';
	for(int i = 1;i <= 9;i++)pre[0][i] = -1;
	for(int i = 1;i <= n + 1;i++){
		for(int j = 1;j <= 9;j++)pre[i][j] = pre[i-1][j];
		pre[i][a[i]] = i;
	}
	for(int i = n + 1;i >= 1;i--){
		f[i][a[i]] = i;
		for(int j = a[i]+1;j <= 200;j++){
			f[i][j] = f[i][j - 1];
			for(int k = 1;k <= 9;k++){
				if(j < k)continue;
				int tmp = f[i][j - k] + 1;//w <= tmp
				f[i][j] = max(f[i][j],f[pre[tmp][k] + 1][j - k]);
			}
		}
	}
	for(int i = 0;i <= 200;i++)
		if(f[1][i] >= n)return printf("%d\n",i),0;
 
	return cerr<<clock()<<"ms"<<endl,0;

}