Submission #342340

#TimeUsernameProblemLanguageResultExecution timeMemory
342340jeroenodbPalindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
1 ms384 KiB
#include <iostream> #include <vector> #include <bitset> #include <cassert> #include <algorithm> #include <cstring> using namespace std; #define all(x) begin(x),end(x) typedef long long ll; const int mxN = 1e5+1; ll dp[18][11][11][2]; vector<int> dig; ll recur(int i=0, int p=10, int pp=10, bool free=false) { if(i==dig.size()) return 1; if(dp[i][p][pp][free]) { return dp[i][p][pp][free]-1; } dp[i][p][pp][free]++; int limit = free?9:dig[i]; for(int d=0;d<=limit;++d) { if(d==p or d==pp) continue; int tmp = d; if(p==10 and d==0) { tmp=10; } dp[i][p][pp][free]+=recur(i+1,tmp,p,free or d!=dig[i]); } return dp[i][p][pp][free]-1; } ll solve(ll a) { if(a==-1) return 0; memset(&dp[0][0][0][0], 0,sizeof(dp)); dig.clear(); while(a!=0) { dig.push_back(a%10); a/=10; } reverse(all(dig)); return recur(); } int main() { ll a,b; cin >> a >> b; cout << solve(b) - solve(a-1) << endl; }

Compilation message (stderr)

numbers.cpp: In function 'll recur(int, int, int, bool)':
numbers.cpp:14:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     if(i==dig.size()) return 1;
      |        ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...