Submission #252183

#TimeUsernameProblemLanguageResultExecution timeMemory
252183m3r8Palindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
1 ms384 KiB
#include <stdio.h> #include <vector> #include <string.h> #define ll long long ll dp[10][10][20]; ll sm[20]; std::vector<int> num; void con(ll a){ num.clear(); while(a){ num.push_back(a%10); a /= 10; }; }; ll calc(ll a){ if(a < 0)return 0; if(a < 10)return a+1; if(a < 100){ ll tmp = a/10; if(tmp > a % 10)return a - tmp + 2; else return a - tmp + 1; }; con(a); memset(dp,0,sizeof(dp)); memset(sm,0,sizeof(sm)); sm[1] = 10; for(int i = 0;i<10;i++){ for(int j = 0;j<10;j++){ if(i != j){ dp[i][j][2] = 1; }; if(i != 0){ sm[2] += dp[i][j][2]; }; }; }; for(int i = 3;i<20;i++){ for(int j = 0;j<10;j++){ for(int k = 0;k<10;k++){ for(int l = 0;l<10;l++){ if(j != k && j != l){ dp[j][k][i] += dp[k][l][i-1]; }; }; if(j != 0){ sm[i] += dp[j][k][i]; }; }; }; }; ll erg = 0; int prev = -1; int pprev = -1; for(int i = 0;i<num.size();i++){ int mx = num[num.size()-1-i]; int lf = num.size() - i; if(lf >= 2){ int start = prev == -1 ? 1 : 0; for(int j = start;j<mx;j++){ if(j != prev && j != pprev){ for(int k = 0;k<10;k++){ if(k != prev){ erg += dp[j][k][lf]; }; }; }; }; }else{ for(int j = 0;j<=mx;j++){ if(j != prev && j != pprev)erg++; }; }; if(pprev == mx || prev == mx)break; pprev = prev; prev = mx; }; for(int i = 1;i<num.size();i++){ erg += sm[i]; }; return erg; }; int main(void){ ll a,b; scanf("%lld %lld",&a,&b); ll erg = calc(b) - calc(a-1); printf("%lld\n",erg); return 0; };

Compilation message (stderr)

numbers.cpp: In function 'long long int calc(long long int)':
numbers.cpp:56:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i<num.size();i++){
                 ~^~~~~~~~~~~
numbers.cpp:79:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1;i<num.size();i++){
                 ~^~~~~~~~~~~
numbers.cpp: In function 'int main()':
numbers.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&a,&b);
   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...