Submission #855190

#TimeUsernameProblemLanguageResultExecution timeMemory
855190ThylOnePalindrome-Free Numbers (BOI13_numbers)C++14
39.17 / 100
2 ms600 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; string limit; int dpTab[2][20][12][12]; int dp(bool L,int pos=0,int last1=10,int last2=10){ if(pos==limit.size())return 1; if(dpTab[L][pos][last1][last2]!=-1) return dpTab[L][pos][last1][last2]; int cnt=0; int borne = (limit[pos]-'0'); if(!L)borne=9; for(int digit=0;digit<=borne;digit++){ if(digit!=last1 && digit!=last2){ int L2 = (borne==digit); if(L==false)L2=false; cnt+=dp(L2,pos+1,digit,last1); } } dpTab[L][pos][last1][last2] = cnt; return dpTab[L][pos][last1][last2]; } void setDp(ll lim){ limit = to_string(lim); for(int b=0;b<2;b++){ for(int pos=0;pos<20;pos++){ for(int last1=0;last1<=10;last1++){ for(int last2=0;last2<=10;last2++){ dpTab[b][pos][last1][last2]=-1; } } } } } signed main(){ ll a,b; cin>>a>>b; int cnt=0; setDp(b); cnt+=dp(true,0,10,10); setDp(a-1); cnt-=dp(true,0,10,10); cout<<cnt<<endl; return 0; }

Compilation message (stderr)

numbers.cpp: In function 'int dp(bool, int, int, int)':
numbers.cpp:8:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  if(pos==limit.size())return 1;
      |     ~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...