add some
This commit is contained in:
72
storage/aloha/cpp/2026-cherry-div1-E.cpp
Normal file
72
storage/aloha/cpp/2026-cherry-div1-E.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define let auto
|
||||
#define fn auto
|
||||
#define usize size_t
|
||||
using namespace std;
|
||||
|
||||
const usize MOD = 1'000'000'007;
|
||||
|
||||
fn fastio() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
}
|
||||
|
||||
fn count_ilove(usize x, const vector<usize> &hates) -> usize {
|
||||
if (x == 0) return 0;
|
||||
|
||||
string s = to_string(x);
|
||||
usize n = s.size();
|
||||
|
||||
vector<vector<vector<usize>>> dp(n + 1,
|
||||
vector<vector<usize>>(2, vector<usize>(2, 0)));
|
||||
dp[0][1][0] = 1;
|
||||
|
||||
for (usize pos = 0; pos < n; pos++) {
|
||||
for (usize tight = 0; tight <= 1; tight++) {
|
||||
for (usize started = 0; started <= 1; started++) {
|
||||
usize limit = tight ? (s[pos] - '0') : 9;
|
||||
|
||||
for (usize digit = 0; digit <= limit; digit++) {
|
||||
bool is_hated = false;
|
||||
for (usize h: hates) {
|
||||
if (h == digit) {
|
||||
is_hated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_hated) continue;
|
||||
|
||||
bool next_started = started || (digit != 0);
|
||||
usize next_tight = (tight && digit == limit) ? 1 : 0;
|
||||
|
||||
if (!next_started && pos == n - 1) continue;
|
||||
|
||||
dp[pos + 1][next_tight][next_started] += dp[pos][tight][started];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usize result = 0;
|
||||
for (usize tight = 0; tight <= 1; tight++) {
|
||||
result += dp[n][tight][1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
fastio();
|
||||
|
||||
usize n, l, r;
|
||||
cin >> n >> l >> r;
|
||||
vector<usize> hates(n);
|
||||
for (usize i = 0; i < n; i++) {
|
||||
cin >> hates[i];
|
||||
}
|
||||
|
||||
usize ret = (count_ilove(r, hates) + 2 * MOD - (count_ilove(l - 1, hates))) % MOD;
|
||||
cout << ret % MOD << "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user