Submission #1192137

#TimeUsernameProblemLanguageResultExecution timeMemory
119213727augainPalindrome-Free Numbers (BOI13_numbers)C++20
72.50 / 100
1 ms400 KiB
#include <bits/stdc++.h> using namespace std; #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1LL) using ll = long long; const int mxn = 9 + 1e6; const int inf = 0x3f3f3f3f; const ll lnf = 0x3f3f3f3f3f3f3f3f; string s; ll dp[18][11][11][2]; ll DP(int id, int lst1, int lst2, bool f) { if (id == (int) (s.size())) { return true; } if (lst1 != 10 && lst2 != 10 && dp[id][lst1][lst2][f] != -1) { return dp[id][lst1][lst2][f]; } ll res = 0; for (int c = 0; c <= (f ? s[id] - '0' : 9); ++c) { bool nwf = false; if (f && c == s[id] - '0') { nwf = true; } if (c != lst1 && c != lst2) { res += DP(id + 1, c, lst1, nwf); } } return dp[id][lst1][lst2][f] = res; } ll solve(ll x) { s = to_string(x); memset(dp, -1, sizeof(dp)); return DP(0, 10, 10, true); } void _27augain(void) { ll l, r; cin >> l >> r; cout << solve(r) - solve(l - 1) << "\n"; } int32_t main(void) { #define task "27augain" cin.tie(0)->sync_with_stdio(0); for (string iext : {"in", "inp"}) { if (fopen((task "." + iext).c_str(), "r")) { freopen((task "." + iext).c_str(), "r", stdin); freopen(task ".out", "w", stdout); } } int testcase = 1; // cin >> testcase; while (testcase--) { _27augain(); } return 0; }

Compilation message (stderr)

numbers.cpp: In function 'int32_t main()':
numbers.cpp:53:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |       freopen((task "." + iext).c_str(), "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:54:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |       freopen(task ".out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...