题目: https://codeforces.com/gym/104466/problem/G
思想:数位dp,求l-r每个数字出现的最多次数,就是每个数x 然后10*x+x,判断是否在l,r之间,便可以找到数字出现的最长次数
代码:
// Problem: G. German Conference for Public Counting
// Contest: Codeforces - 2023-2024 ICPC German Collegiate Programming Contest (GCPC 2023)
// URL: https://codeforces.com/gym/104466/problem/G
// Memory Limit: 512 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
ll n;
cin>>n;
if(n>=0&&n<=9){
cout<<n+1<<"\n";
return 0;
}
map<int,ll> mp;
for(int i=1;i<=9;i++){
ll num=0,x=i;
while(x<=n){
//cout<<x<<' ';
mp[i]++;
x=x*10+i;
}
}
string a=to_string(n);
int ans=a.size()-1;
for(int i=0;i<=9;i++){
//cout<<mp[i]<<' ';
ans+=mp[i];
}
cout<<ans<<"\n";
return 0;
}