Submission #248568

#TimeUsernameProblemLanguageResultExecution timeMemory
248568eohomegrownappsPalindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; string s; ll dpv[20][11][11][2]; ll dp(int ind, int secondlast, int last, bool isSame){ if (ind==s.size()){ return 1; } if (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&&last!=10) || (i==secondlast&&secondlast!=10)){continue;} int ival = i; if (i==0&&last==10){ ival = 10; } total+=dp(ind+1,last,ival,isSame&&ival==(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<11; j++){ for (int k = 0; k<11; 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,10,10,true); if (a>=0){ s=to_string(a); initdp(); tot-=dp(0,10,10,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...