Submission #990358

#TimeUsernameProblemLanguageResultExecution timeMemory
990358PaDiPalindrome-Free Numbers (BOI13_numbers)C++14
73.75 / 100
1 ms612 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define int long long #define pb push_back #define mp make_pair #define READS(x); string x;cin >> x; #define READ(x); int x;cin >> x; #define DOUREAD(x,y); int x,y;cin >> x >> y; #define TRIREAD(x,y,z); int x,y,z;cin >> x >> y >> z; int dp[25][15][15][2][2]; string S; int LIM; int F(int POS,int PRE,int CUR,int FLAG,int ZERO){ if(POS == LIM) return 1; if(dp[POS][PRE][CUR][FLAG][ZERO] != -1) return dp[POS][PRE][CUR][FLAG][ZERO]; int& ANS = dp[POS][PRE][CUR][FLAG][ZERO]; ANS = 0; int BOUND; if(FLAG) BOUND = 9; else BOUND = S[POS+1]-'0'; for(int d = 0 ; d <= BOUND ; d++){ if(d == CUR) continue; if(d == PRE) continue; int BOOL; if(FLAG) BOOL = 1; else{ if(d < BOUND) BOOL = 1; else BOOL = 0; } int NPRE = PRE; int NCUR = CUR; int NZ = (ZERO|(d > 0)); if(NZ){ NPRE = CUR; NCUR = d; } ANS += F(POS+1,NPRE,NCUR,BOOL,NZERO); } return ANS; } signed main(){fast DOUREAD(L,R); if(L <= 1){ memset(dp,-1,sizeof(dp)); S = to_string(R); LIM = S.size(); S = '_' + S; int ANZ = F(0,10,10,0,0); if(L == 1) cout << ANZ - 1 << '\n'; else cout << ANZ << '\n'; } if(L > 1){ L--; S = to_string(L); LIM = S.size(); S = '_' + S; memset(dp,-1,sizeof(dp)); int ANSL = F(0,10,10,0,0); memset(dp,-1,sizeof(dp)); S = to_string(R); LIM = S.size(); S = '_' + S; int ANSR = F(0,10,10,0,0); cout << ANSR - ANSL << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...