Submission #631301

#TimeUsernameProblemLanguageResultExecution timeMemory
631301Tuanlinh123Palindrome-Free Numbers (BOI13_numbers)C++17
44.58 / 100
1 ms352 KiB
#include<bits/stdc++.h> #define ll long long #define ld long double #define pll pair<ll,ll> #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; #define LOCALIO "C:/Users/admin/Documents/Code/freopen/" ll dp[20][10][10]; ll calc(ll a) { if (a==-1) return 0; if (a<10) return a+1; vector <ll> num; while (a>0) { num.pb(a%10); a/=10; } reverse(num.begin(), num.end()); ll last=-1, last2=-1, last3=-1, ans=0, n=num.size(); for (ll i=0; i<num.size(); i++) { if ((last3==last || last2==last) && last!=-1) break; ll dig=num[i]; if (i==0) { for (ll j=1; j<dig; j++) for (ll k=0; k<10; k++) { // cout << n-i << " " << j << " " << k << " " << dp[n-i][j][k] << "\n"; ans+=dp[n-i][j][k]; } last3=last2; last2=last; last=dig; continue; } if (i==1) { for (ll j=0; j<dig; j++) { // cout << n-i+1 << " " << last << " " << j << " " << dp[n-i+1][last][j] << "\n"; ans+=dp[n-i+1][last][j]; } last3=last2; last2=last; last=dig; continue; } for (ll j=0; j<=dig; j++) if (j!=last2) { // cout << n-i+1 << " " << last << " " << j << " " << dp[n-i+1][last][j] << "\n"; ans+=dp[n-i+1][last][j]; } last3=last2; last2=last; last=dig; } // cout << ans << " "; for (ll i=1; i<n; i++) { if (i==1) { ans+=10; continue; } for (ll j=1; j<10; j++) for (ll k=0; k<10; k++) { // cout << i << " " << j << " " << k << " " << dp[i][j][k] << "\n"; ans+=dp[i][j][k]; } } // for (ll i=0; i<num.size(); i++) // cout << num[i]; // cout << " "; // cout << ans << "\n"; return ans; } int main() { #ifdef LOCAL freopen( LOCALIO "input.txt","r",stdin) ; freopen( LOCALIO "output.txt","w",stdout) ; #endif ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr); // freopen("FIBONACCI.inp","r",stdin); // freopen("FIBONACCI.out","w",stdout); for (ll i=2; i<20; i++) { for (ll j=0; j<10; j++) { for (ll k=0; k<10; k++) { if (j==k) { dp[i][j][k]=0; continue; } if (i==2) { dp[i][j][k]=1; continue; } for (ll z=0; z<10; z++) if (z!=j) dp[i][j][k]+=dp[i-1][k][z]; // cout << i << " " << j << " " << k << " " << dp[i][j][k] << "\n"; } } } ll a, b; cin >> a >> b; cout << calc(b)-calc(a-1); }

Compilation message (stderr)

numbers.cpp: In function 'long long int calc(long long int)':
numbers.cpp:30:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (ll i=0; i<num.size(); i++)
      |                  ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...