제출 #95269

#제출 시각아이디문제언어결과실행 시간메모리
95269rkocharyanPalindrome-Free Numbers (BOI13_numbers)C++14
71.25 / 100
3 ms660 KiB
#include <bits/stdc++.h> using namespace std; const int N = 20; int n; long long dp[N][2]; string s; long long calc(int pos, int f, int c1, int c2, int c3) { if((c2 == c3 && c2 != -1 && c3 != -1) || (c1 == c3 && c1 != -1 && c3 != -1)) return 0; if(pos == n) return 1; auto &res = dp[pos][f]; if(res != -1) { return res; } res = 0; int lmt = f ? 9 : s[pos] - '0'; for(int i = pos == 0 ? 1 : 0; i <= lmt; i++) { int nf = f; if(i < lmt) nf = 1; res += calc(pos + 1, nf, c2, c3, i); } return res; } long long solve(string &x) { s = x; n = (int) x.size(); memset(dp, -1, sizeof dp); return calc(0, 0, -1, -1, -1); } int main() { ios::sync_with_stdio(0); cin.tie(0); long long l, r; cin >> l >> r; l--; if(l == -1) assert(false); string a, b; a = to_string(l); b = to_string(r); cout << solve(b) - solve(a) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...