제출 #495753

#제출 시각아이디문제언어결과실행 시간메모리
495753AchileasPalindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
2 ms464 KiB
// // Created by Le Gia Khanh // /* pray for luck UwU _ ooOoo o8888888o 88" . "88 (| -_- |) O\ = /O ___/`---'\___ .' \| |// `. / \||| : |||// \ / ||||| -:- ||||| \ | | \ - /'| | | | \_| `\`---'// |_/ | \ .-\__ `-. -'__/-. / ___. .' /--.--\ . .'___ ."" '< `.___\_<|>_/___.' _> \"". | | : - \. ;`. _/; .'/ / .' ; | \ \ -. \_\_. _.'_/_/ -' _.' / ===========`-.`___`-.__\ \___ /__.-'.'.-'================ `=--=-' hjw */ #include <bits/stdc++.h> using namespace std; #define div awfiuskjdnvknj #define fi first #define pb push_back #define mp make_pair #define TASK "TASK" #define se second #define timeclock printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC); // 1 << __builtin_ctz(x). Compute the biggest power of 2 that is a divisor of x. Example: f(12) = 4 #define builtin_ctz __builtin_ctz // 1 << (32 - __builtin_clz (x - 1)) Compute the smallest power of 2 that is not smaller than x. Example: f(12) = 16 #define builtin_clz builtin_clz //count bit 1 #define __builtin_popcount __builtin_popcountll template<class X, class Y> bool minimize(X &x, const Y &y) { X eps = 1e-9; if (x > y + eps) { x = y; return true; } else return false; } template<class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + eps < y) { x = y; return true; } else return false; } long long dp[20][11][11][2][2]; long long solve(bool ok, bool flag, int cur, int pre1, int pre2, string x){ if (cur == x.size()){ // cout << trace << "\n"; return 1; } if (dp[cur][pre1][pre2][ok][flag] != -1) return dp[cur][pre1][pre2][ok][flag]; int m = ok ? x[cur] - '0' : 9; long long res = 0; for (int i = 0; i <= m; i++){ if (pre1 == i || pre2 == i) continue; int new_flag = flag && i == 0; int new_pre1 = 10, new_pre2 = 10; if (!new_flag) new_pre1 = pre2, new_pre2 = i; res += solve(ok & (i == m), new_flag, cur + 1, new_pre1, new_pre2, x); } return dp[cur][pre1][pre2][ok][flag] = res; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); long long a, b; cin >> a >> b; memset(dp, -1, sizeof dp); long long L = solve(1, 1, 0, 10, 10, to_string(a - 1)); memset(dp, -1, sizeof dp); long long R = solve(1, 1, 0, 10, 10, to_string(b)); cout << R - L; return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */ // #ifdef ONLINE_JUDGE // freopen("input.inp", "r", stdin); // freopen("output.out", "w", stdout); // #endif

컴파일 시 표준 에러 (stderr) 메시지

numbers.cpp: In function 'long long int solve(bool, bool, int, int, int, std::string)':
numbers.cpp:68:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     if (cur == x.size()){
      |         ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...