제출 #1128835

#제출 시각아이디문제언어결과실행 시간메모리
1128835AgageldiPalindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
2 ms1864 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 400005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() ll n, t, a[N], m, ret, l, r, dp[20][10][10][10][10]; ll solve(int pos,int last_dig,int pre_last_digit,int flag,int big_flag) { if(pos == 20) { return 1; } ll ret = dp[pos][last_dig][pre_last_digit][flag][big_flag]; if(~ret) { return ret; } ret = 0; /* flag: 0 baslamady flag: 1 baslanymdan bir sifr gecdi flag: 2 baslanymdan bir sifrdan kop boldy bigflag: eger prefix-in hemmesi den bolsa onda 0 else 1 */ for(int i = 0; i < 10; i++) { if(flag >= 1 && last_dig == i) continue; if(flag == 2 && pre_last_digit == i) continue; if(big_flag == 0 && i > a[pos]) continue; int new_big_flag = (big_flag | (i < a[pos])); int new_flag = min(2,flag + (flag | (i != 0))); ret += solve(pos + 1,i,last_dig,new_flag,new_big_flag); } dp[pos][last_dig][pre_last_digit][flag][big_flag] = ret; return ret; } ll f(ll x){ if(x < 0) return 0; memset(dp,-1,sizeof dp); for(int i = 19; i >= 0; i--) { a[i] = x % 10; x /= 10; } return solve(0,0,0,0,0); } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> l >> r; cout << f(r) - f(l-1) <<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...