Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- constexpr int N = 1e5 + 5;
- constexpr int Inf = 999999999;
- int n, s[N], p[N];
- int a, b;
- void Read()
- {
- cin >> a >> b;
- for(int i = a; i <= b; ++i)
- s[++n] = i;
- }
- // Compare x and y
- bool com(int x, int y) {
- string a, b;
- while(x) {
- a.push_back(char(x % 10 + '0'));
- x /= 10;
- }
- while(y) {
- b.push_back(char(y % 10 + '0'));
- y /= 10;
- }
- reverse(a.begin(), a.end());
- reverse(b.begin(), b.end());
- return a < b;
- }
- void Solve() {
- fill_n(p, N, Inf);
- p[0] = 0;
- int ans(0);
- for(int i = 1; i <= n; ++i) {
- int j = lower_bound(p + 1, p + n + 1, s[i], com) - p;
- ans = max(ans, j);
- if(com(s[i], p[j]))
- p[j] = s[i];
- }
- cout << n - ans;
- }
- int main ()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment