Submission #248562

#TimeUsernameProblemLanguageResultExecution timeMemory
248562eohomegrownappsPalindrome-Free Numbers (BOI13_numbers)C++14
39.17 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; string s; int dpv[20][10][10][2]; ll dp(int ind, int secondlast, int last, bool isSame){ if (ind==s.size()){ return 1; } if (secondlast!=-1&&dpv[ind][secondlast][last][isSame]!=-1){ return dpv[ind][secondlast][last][isSame]; } int upper = isSame ? s[ind]-'0' : 9; ll total = 0; for (int i = 0; i<=upper; i++){ if (i==last || i==secondlast){continue;} total+=dp(ind+1,last,i,isSame&&i==(s[ind]-'0')); } if (secondlast!=-1){ dpv[ind][secondlast][last][isSame]=total; } return total; } void initdp(){ 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++){ dpv[i][j][k][l]=-1; } } } } } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); ll a,b; cin>>a>>b; a--; s=to_string(b); initdp(); ll tot = dp(0,-1,-1,true); if (a>=0){ s=to_string(a); initdp(); tot-=dp(0,-1,-1,true); } cout<<tot<<'\n'; }

Compilation message (stderr)

numbers.cpp: In function 'll dp(int, int, int, bool)':
numbers.cpp:10:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (ind==s.size()){
      ~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...