Submission #446197

#TimeUsernameProblemLanguageResultExecution timeMemory
446197callmepandeyPalindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
1 ms380 KiB
/* * The way if it's all predetermined * And the way i should go all my life * I swear to go wherever will be * 'Cause there'll be something to see and to find */ #include "bits/stdc++.h" #define ll long long using namespace std; #define check(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename val1> void __f(const char* name, val1&& value) { cout << name << " = " << value << endl; } template <typename val1, typename... values> void __f( const char* names, val1&& value, values&&... multiplevalue) { const char* comma = strchr( names + 1, ','); cout.write(names, comma - names) << " = " << value << " "; __f(comma + 1, multiplevalue...); } ll a , b; vector <int> digits; ll dp[22][11][11][2][2]; ll memo(ll i,ll l,ll sl,ll st,ll sm){ if(i==digits.size()) return 1; ll &ans = dp[i][l][sl][st][sm]; if(ans != -1) return ans; ans = 0; if(st==0){ ans += memo(i+1,l,sl,st,1); if(sm){ for(int j = 1;j<=9;j++){ ans += memo(i+1,j,l,1,1); } } else { for(ll j = 1;j<digits[i];j++){ ans += memo(i+1,j,l,1,1); } ans += memo(i+1,digits[i],l,1,0); } } else { if(sm){ for(int j = 0;j<=9;j++){ if(j==l or j==sl) continue; ans += memo(i+1,j,l,1,1); } } else { for(ll j = 0;j<digits[i];j++){ if(j==l or j==sl) continue; ans += memo(i+1,j,l,1,1); } if(digits[i]!=l and digits[i]!=sl) ans += memo(i+1,digits[i],l,1,0); } } return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> a >> b; while(b){ digits.push_back(b%10); b = b/10; } auto init = [&](){ for(int i = 0;i<=20;i++){ for(int j = 0;j<=10;j++){ for(int k = 0;k<=10;k++){ for(int l = 0;l<2;l++){ dp[i][j][k][l][0] = dp[i][j][k][l][1] = -1; } } } } }; reverse(digits.begin() , digits.end()); init(); ll ans = memo(0 , 10 , 10 , 0 , 0); a--; if(a > -1){ init(); digits.clear(); while(a){ digits.push_back(a%10); a /= 10; } reverse(digits.begin() , digits.end()); ll ans2 = memo(0,10,10,0,0); ans -= ans2; } cout << ans; cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << "\n"; return 0; }

Compilation message (stderr)

numbers.cpp: In function 'long long int memo(long long int, long long int, long long int, long long int, long long int)':
numbers.cpp:24:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   if(i==digits.size())
      |      ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...