제출 #779042

#제출 시각아이디문제언어결과실행 시간메모리
779042vjudge1Palindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
1 ms364 KiB
#define local
#ifndef local
#include ""
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 21;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
mt19937 rng(1);
 
int n;
 
int dp[19][100][3];
 
int cal(int x){
    if(x < 0) return 0;
    for(int i = 0; i <= 18; i++){
        for(int j = 0; j < 100; j++){
            for(int k = 0; k < 3; k++) dp[i][j][k] = 0;
        }
    }
    if(x <= 99){
        int ans = 0;
        for(int i = 0; i <= x; i++){
            if(i && !(i % 11)) continue;
            ans++;
        }
        return ans;
    }
    int xx = x;
    while(xx >= 100) xx /= 10;
    //cout << xx << "\n";
    for(int i = 0; i < 10; i++) dp[1][i][0] = 1;
    for(int i = 10; i < 100; i++){
        if(!(i % 11)) continue;
        //cout << i << "\n";
        int val;
        if(i < xx) val = 0;
        else if(i == xx) val = 1;
        else val = 2;
        dp[2][i][val] = 1; 
    }
    xx = x;
    int dig = 0;
    vector<int> v;
    while(xx){
        v.pb(xx % 10);
        dig++;
        xx /= 10;
    }
    v.pb(-1);
    reverse(v.begin(), v.end());
    for(int i = 2; i < dig; i++){
        for(int lst = 0; lst < 100; lst++){
            for(int state = 0; state < 3; state++){
                for(int nxt = 0; nxt < 10; nxt++){
                    if(nxt == lst%10) continue;
                    if(nxt == lst/10) continue;
                    int temp = (lst % 10) * 10 + nxt;
                    int nwstate = state;
                    if(nwstate == 1 && nxt > v[i + 1]) nwstate = 2;
                    if(nwstate == 1 && nxt < v[i + 1]) nwstate = 0;
                    //nwstate &= (nxt == v[i + 1]);
                    dp[i + 1][temp][nwstate] += dp[i][lst][state];
                }
            }
        }
    }
    int tot = 0;
    for(int temp = 1; temp <= dig; temp++){
        for(int i = 0; i < 100; i++){
            for(int j = 0; j < 3; j++){
                if(temp == dig && j == 2) continue;
              //  cout << temp << " " << i << " " << j << " " << dp[temp][i][j] << "\n";
                tot += dp[temp][i][j];
            }
        }
    }
    return tot;
}
 
#ifdef local
void process(){
    int a, b;
    cin >> a >> b;
   // cout << cal(a - 1) << " " << cal(b) << "\n";
    cout << cal(b) - cal(a - 1);
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	process();
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...