| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 528315 | CherryMagic | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int a,b;
vector<int> num;
long dp[22][10][10][2][2];
long call(int pos, int dig1, int dig2, int notpal, int f){
if (pos == num.size()){
if (dig1 != dig2 && notpal) return 1;
else return 0;
}
if (dp[pos][dig1][dig2][notpal][f] != -1)
return dp[pos][dig1][dig2][notpal][f];
long res = 0;
int lmt;
if (f == 0){
lmt = num[pos];
}
else{
lmt = 9;
}
for (int dgt=0;dgt <= lmt; dgt++){
int ndig1, ndig2, nnotpal = notpal, nf=f;
if (f == 0 && dgt < lmt) nf = 1;
if ((pos >=2 && dgt == dig1) || (pos>=1 && dgt == dig2)) nnotpal=0;
if (pos >= 1) ndig1 = dig2;
else ndig1 = 0;
ndig2 = dgt;
if (nnotpal) res += call(pos+1, ndig1, ndig2, nnotpal, nf);
}
return dp[pos][dig1][dig2][notpal][f] = res;
}
int solve(int a){
num.clear();
while (a > 0){
num.push_back(a%10);
a/=10;
}
reverse(num.begin(), num.end());
memset(dp, -1, sizeof(dp));
return call(0, 0, 0, 1, 0);
}
int main()
{
cin >> a >> b;
if (a == 0) cout << solve(b)<<endl;
else cout << solve(b) - solve(a-1) << endl;
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
