QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296166 | #7951. Magic Cards | defyers# | WA | 0ms | 3624kb | C++17 | 3.7kb | 2024-01-02 12:44:12 | 2024-01-02 12:44:12 |
Judging History
answer
/*
5 50 100
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
1
0
0
1 2 3 4 5 6 7 8 9
1 2 3
0 1 2 3 4 5 6 7 8 9
4
0 1 2 3 4 5 6 7 8
4
9
*/
#include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using ll = long long;
using pii = pair<int, int>;
int p2 = 0, p3 = 0, p5 = 0, p7 = 0;
const ll mod = 1000000007;
ll g(int len, vector<int> &l, vector<int> &r) {
int P2 = p2 + 1;
int P3 = p3 + 1;
int P5 = p5 + 1;
int P7 = p7 + 1;
for (int i = 0; i < len; i++) if (l[i] > r[i]) return 0;
vector dp(P2, vector(P3, vector(P5, vector(P7, vector(2, 0ll)))));
dp[0][0][0][0][0] = 1;
for (int _ = 0; _ < len; _++) {
vector ndp(P2, vector(P3, vector(P5, vector(P7, vector(2, 0ll)))));
for (int c = l[_]; c <= r[_]; c++) {
cout << c << " ";
for (int i = 0; i < P2; i++) {
for (int j = 0; j < P3; j++) {
for (int k = 0; k < P5; k++) {
for (int l = 0; l < P7; l++) {
for (int h = 0; h < 2; h++) {
if (c == 0) {
ndp[i][j][k][l][1] += dp[i][j][k][l][h];
}
if (c == 1) {
ndp[i][j][k][l][h] += dp[i][j][k][l][h];
}
if (c == 2) {
ndp[min(i + 1, p2)][j][k][l][h] += dp[i][j][k][l][h];
}
if (c == 3) {
ndp[i][min(j + 1, p3)][k][l][h] += dp[i][j][k][l][h];
}
if (c == 4) {
ndp[min(i + 2, p2)][j][k][l][h] += dp[i][j][k][l][h];
}
if (c == 5) {
ndp[i][j][min(k + 1, p5)][l][h] += dp[i][j][k][l][h];
}
if (c == 6) {
ndp[min(i + 1, p2)][min(j + 1, p3)][k][l][h] += dp[i][j][k][l][h];
}
if (c == 7) {
ndp[i][j][k][min(l + 1, p7)][h] += dp[i][j][k][l][h];
}
if (c == 8) {
ndp[min(i + 3, p2)][j][k][l][h] += dp[i][j][k][l][h];
}
if (c == 9) {
ndp[i][min(j + 2, p3)][k][l][h] += dp[i][j][k][l][h];
}
}
}
}
}
}
}
for (int i = 0; i < P2; i++) {
for (int j = 0; j < P3; j++) {
for (int k = 0; k < P5; k++) {
for (int l = 0; l < P7; l++) {
for (int h = 0; h < 2; h++) {
dp[i][j][k][l][h] = (ndp[i][j][k][l][h]) % mod;
}
}
}
}
}
cout << endl;
}
ll ret = 0;
for (int i = 0; i < P2; i++) {
for (int j = 0; j < P3; j++) {
for (int k = 0; k < P5; k++) {
for (int l = 0; l < P7; l++) {
ret += dp[i][j][k][l][1];
}
}
}
}
ret += dp[p2][p3][p5][p7][0];
return ret % mod;
}
ll f(ll n) {
if (n == 0) return 0;
ll ans = 0;
{
vector<int> L, R;
L.push_back(1), R.push_back(9);
for (ll i = 1, x = 10; n >= x; i++, x *= 10) {
ans += g(i, L, R);
L.push_back(0), R.push_back(9);
}
}
{
string s = to_string(n);
int len = s.size();
vector<int> L, R;
for (int i = 0; i < len; i++) {
L.push_back(s[i] - '0');
R.push_back(s[i] - '0');
}
for (int i = 0; i < len; i++) {
auto L2 = L, R2 = R;
if (i == 0) L2[i] = 1;
else L2[i] = 0;
R2[i]--;
for (int j = i + 1; j < len; j++) {
L2[j] = 0;
R2[j] = 9;
}
ans += g(len, L2, R2);
}
ans += g(len, L, R);
}
return ans;
}
void solve(int TC) {
ll k, l, r;
cin >> k >> l >> r;
while (k % 2) {
p2++;
k /= 2;
}
while (k % 3) {
p3++;
k /= 3;
}
while (k % 5) {
p5++;
k /= 5;
}
while (k % 7) {
p7++;
k /= 7;
}
ll ans = f(r) - f(l - 1);
ans = (ans % mod + mod) % mod;
cout << ans << "\n";
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
12 4 6 3 1 9 7 11 3 5 2 10 3 6 7 11 4 5 6 7 6 12 8 11 10 9 12 9 YYNY NNNY YNNN
output:
1 2 3 4 5 6 1 2 3 0
result:
wrong answer 1st lines differ - expected: '11', found: '1 2 3 4 5 '