Submission #821256

#TimeUsernameProblemLanguageResultExecution timeMemory
821256vjudge1Palindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
1 ms340 KiB
// teddybear's code // the one who loves NBP // noe the second // goal: 0 / 8 // get medal in APIO (like TKN) //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") // prob: #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define FOR(i,n) for (int i = 0; i<n; i++) using ll = long long; using ull = unsigned long long; ll n,m,t; ll cnt = 0; const int maxn = 1e5; const ll mod = 1e9 + 7; #define Y "YES" #define N "NO" int a[1005][1005]; bool visited[1005][1005]; int dist[1005][1005]; int w,h; int fx[4] = {-1, 1, 0, 0}; int fy[4] = {0, 0, -1, 1}; queue <pair<int,int>> q; string s; ll num[20][2][11][11]; ll dp(ll pos, ll eq, ll start, ll last1, ll last2) { if (pos == s.size()) { return 1; } ll ans = 0; if (num[pos][eq][last1][last2] != -1) { return num[pos][eq][last1][last2]; } ll mxnum; if (eq) { mxnum = s[pos] - '0'; } else mxnum = 9; if (!start) { for (int dig = 0; dig<=mxnum; dig++) { ll newstart; if (dig != 0) newstart = 1; else newstart = 0; ll neweq = eq & (dig == mxnum); if (newstart) { ans += dp(pos+1,neweq, newstart, dig, last2); } else { ans += dp(pos+1,neweq, newstart, last1, last2); } } } else { for (int dig = 0; dig <= mxnum; dig++) { if (dig == last1 || dig == last2) continue; ll newstart = start; ll neweq = eq & (dig == mxnum); //ll tmp = dig; ll ls2 = last1; ll ls1 = dig; ans += dp(pos+1, neweq, newstart, ls1, ls2); } } return num[pos][eq][last1][last2] = ans; } ll DP(ll val) { if (val < 0) return 0; s = to_string(val); memset(num, -1, sizeof(num)); return dp(0,1,0,-1,-1); } void solve() { cin >> n >> m; cout << DP(m) - DP(n-1); } void init() { int te = 1; //cin >> te; while (te--) { solve(); } } void preprocess() { } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //cin.tie(0); cout.tie(0); //freopen(".inp", "r", stdin); //freopen(".out", "w", stdout); init(); preprocess(); //solve(); return 0; }

Compilation message (stderr)

numbers.cpp: In function 'll dp(ll, ll, ll, ll, ll)':
numbers.cpp:39:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  if (pos == s.size())
      |      ~~~~^~~~~~~~~~~
numbers.cpp: In function 'll _Z2DPx.part.0(ll)':
numbers.cpp:45:31: warning: array subscript -1 is below array bounds of 'll [11]' {aka 'long long int [11]'} [-Warray-bounds]
   45 |  if (num[pos][eq][last1][last2] != -1)
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~^
numbers.cpp:90:34: warning: array subscript -1 is below array bounds of 'll [11]' {aka 'long long int [11]'} [-Warray-bounds]
   90 |  return num[pos][eq][last1][last2] = ans;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~^
numbers.cpp:90:34: warning: array subscript -1 is below array bounds of 'll [11]' {aka 'long long int [11]'} [-Warray-bounds]
   90 |  return num[pos][eq][last1][last2] = ans;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...