Submission #821808

#TimeUsernameProblemLanguageResultExecution timeMemory
821808ThanhsPalindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
1 ms340 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long typedef long double ld; typedef vector<int> vi; typedef vector<vi> vvi; typedef stack<int> si; typedef queue<int> qi; typedef deque<int> di; typedef pair<int, int> pii; typedef vector<pii> vpii; #define endl '\n' #define pb push_back #define FOR(i,g,b) for(int i = g; i <= b; i++) #define BACK(i,g,b) for(int i = g; i >= b; i--) #define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define fi first #define se second #define gcd __gcd #define setmin(x,y) x=min((x),(y)) #define setmax(x,y) x=max((x),(y)) const int MAXN=(1e6)+5; const int inf=1e18; const int MOD=1e9+7; int dp[20][11][11][2][2],a,b,cnt=0; vi dig; int bt(int idx,int p1,int p2,bool k1,bool k2) { cnt++; if(idx==(int)(dig.size())) return 1; if(~dp[idx][p1][p2][k1][k2]) return dp[idx][p1][p2][k1][k2]; int res=0; FOR(i,0,(k1?9:dig[idx])) if(i!=p1&&i!=p2) res+=bt(idx+1,p2,(!i&&!k2?10:i),k1|(i<dig[idx]),k2|(i>0)); return dp[idx][p1][p2][k1][k2]=res; } int solve(int x) { memset(dp,-1,sizeof dp); dig.clear(); while(x) {dig.pb(x%10); x/=10;} reverse(dig.begin(),dig.end()); return bt(0,10,10,0,0); } signed main() { fastIO // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); cin>>a>>b; cout<<solve(b)-solve(a-1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...