제출 #1295596

#제출 시각아이디문제언어결과실행 시간메모리
1295596bakhtiyarnPalindrome-Free Numbers (BOI13_numbers)C++20
26.25 / 100
1 ms588 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int eight[100]; string a, b; int dfs(int i, bool big, bool lit, char last_1, char last_2){ if(i == b.size()) return 1; if(big and lit){ int rest = b.size()-i-1; if(last_1 == '%') return 9*eight[rest]; return eight[rest+1]; } if(lit){ int cnt = '9'-a[i]; if(a[i]+1 <= last_1 and last_1 <= '9') cnt--; if(a[i]+1 <= last_2 and last_2 <= '9') cnt--; if(cnt < 0) cnt = 0; return cnt * dfs(i+1, true, true, last_2, '9') + dfs(i+1, big, lit, last_2, a[i]); } if(big){ int cnt = b[i]-'0'; if('0' <= last_1 and last_1 <= b[i]-1) cnt--; if('0' <= last_2 and last_2 <= b[i]-1) cnt--; if(cnt < 0) cnt = 0; return cnt * dfs(i+1, true, true, last_2, '0') + dfs(i+1, big, lit, last_2, b[i]); } if(a[i] == b[i]) { if(last_1 == a[i] or last_2 == a[i]) return 0; return dfs(i+1, false, false, last_2, a[i]); } int res = 0; for(char j=a[i]+1; j<b[i]; j++){ if(j == last_1 or j == last_2) continue; res += dfs(i+1, true, true, last_2, j); } if(last_2 != a[i] and last_1 != a[i]) res += dfs(i+1, false, true, last_2, a[i]); if(last_2 != b[i] and last_1 != b[i]) res += dfs(i+1, true, false, last_2, b[i]); return res; } void solve(){ cin >> a >> b; while(a.size() < b.size()) a = '0' + a; cout << dfs(0, false, false, '%', '%'); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); eight[0] = 1; for(int i=1; i<=19; i++) eight[i] = eight[i-1] * 8; solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...