Submission #110712

#TimeUsernameProblemLanguageResultExecution timeMemory
110712ckodserPalindrome-Free Numbers (BOI13_numbers)C++14
72.50 / 100
3 ms408 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 19; ll dp[N], dp2[N], dp3[N]; ll Get(ll r) { if (r < 0) return (0); if (r <= 9) return (r + 1); ll m = r, len = 0; int A[N]; while (m) A[len ++] = m % 10, m /= 10; reverse(A, A + len); ll res = dp[len - 1]; for (int i = 0; i < len; i++) { for (int j = 0; j < A[i]; j++) { if (i > 0 && j == A[i - 1]) continue; if (i > 1 && j == A[i - 2]) continue; if (i == 0) res += dp2[len - 1]; else res += dp3[len - i - 1]; } if (i > 0 && A[i] == A[i - 1]) return (res); if (i > 1 && A[i] == A[i - 2]) return (res); } if (A[len - 1] != A[len - 2] && (len == 2 || (A[len - 1] != A[len - 3]))) res ++; return (res); } int main() { dp[1] = 10; for (int i = 2; i < N; i++) dp[i] = dp[i - 1] * 8 + 11; dp2[0] = 1; dp2[1] = 9; for (int i = 2; i < N; i++) dp2[i] = dp2[i - 1] * 8; dp3[0] = 1; dp3[1] = 8; for (int i = 2; i < N; i++) dp3[i] = dp3[i - 1] * 8; ll l, r; scanf("%lld%lld", &l, &r); return !printf("%lld\n", Get(r) - Get(l - 1)); }

Compilation message (stderr)

numbers.cpp: In function 'int main()':
numbers.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &l, &r);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...