제출 #1121073

#제출 시각아이디문제언어결과실행 시간메모리
1121073vjudge1Palindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
2 ms508 KiB
#include<bits/stdc++.h> #define ll long long #define int ll #define pb push_back #define in insert #define fi first #define se second #define vl vector<ll> #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int sz = 3e5 + 5; /// mind this const int MAX = 2e6 + 123; const int BS = 61; const int mod = 998244353; ll dp[18][11][11][2]; string s; ll f(ll ind, ll prv1, ll prv2, bool ok){ if(ind == s.size()){ return 1; } if(dp[ind][prv1][prv2][ok] != -1){ return dp[ind][prv1][prv2][ok]; } ll ans = 0; for(int d = 0; d < 10; d++){ if(d == prv1 || d == prv2){continue;} if(ok && d > (s[ind] - '0')){break;} ll val = d; if(val == 0 && prv1 == 10)val = 10; if(d == (s[ind] - '0')){ ans += f(ind + 1, val, prv1, ok); } else{ ans += f(ind + 1, val, prv1, 0); } } return dp[ind][prv1][prv2][ok] = ans; } void solve(){ ll a, b, i, j; cin >> a >> b; memset(dp, -1, sizeof(dp)); s = to_string(b); ll r = f(0, 10, 10, 1); if(!a){ cout << r << endl; return ; } s = to_string(--a); memset(dp, -1, sizeof(dp)); ll l = f(0, 10, 10, 1); cout << r - l << endl; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; while(t--){ solve(); } } /* */

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

numbers.cpp: In function 'long long int f(long long int, long long int, long long int, bool)':
numbers.cpp:21:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     if(ind == s.size()){
      |        ~~~~^~~~~~~~~~~
numbers.cpp: In function 'void solve()':
numbers.cpp:43:14: warning: unused variable 'i' [-Wunused-variable]
   43 |     ll a, b, i, j;
      |              ^
numbers.cpp:43:17: warning: unused variable 'j' [-Wunused-variable]
   43 |     ll a, b, i, j;
      |                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...