QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462454 | #555. 代码 | LXl491214 | 100 ✓ | 7ms | 3976kb | C++14 | 3.5kb | 2024-07-03 19:43:55 | 2024-07-03 19:43:56 |
Judging History
answer
#include <iostream>
#include <utility>
#include <cstring>
using namespace std;
constexpr const int mod = 1000000007, power_10[]{1, 10, 100, 1000, 10000};
constexpr void UpdInc(int &a, const int b)
{
if ((a += b) >= mod)
a -= mod;
return;
}
constexpr int OFR(const int val)
{
return val >= mod ? val - mod : val;
}
int weight[4], f[101], g1[101][202], g2[101][202], h[101][202];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, K;
cin >> n >> K;
++K;
int siz_weight = 0;
while (power_10[siz_weight] < K)
{
weight[siz_weight] = min(power_10[siz_weight + 1], K) - power_10[siz_weight];
++siz_weight;
}
--siz_weight;
f[0] = 1;
f[1] = 2;
for (int i = 2; i <= n; ++i)
{
const int iM2 = i - 2, end_j = min(iM2, siz_weight);
int v = OFR(f[i - 1] * 2);
for (int j = 0; j <= end_j; ++j)
v = (v + 1ull * weight[j] * f[iM2 - j]) % mod;
for (int j = 0; j <= iM2; ++j)
v = (v + 1ull * f[iM2 - j] * f[j]) % mod;
f[i] = v;
}
g1[0][100] = 1;
for (int i = 1; i <= n; ++i)
{
const int iM2 = i - 2, end_j = min(iM2, siz_weight);
const auto &g1_iM1 = g1[i - 1];
auto &g1_i = g1[i];
memcpy(g1_i + 1, g1_iM1, sizeof(int) * 200);
for (int j = 1; j <= 200; ++j)
UpdInc(g1_i[j - 1], g1_iM1[j]);
for (int j = 0; j <= end_j; ++j)
{
const int weight_j = weight[j];
const auto &target = g1[iM2 - j];
for (int k = 0; k <= 200; ++k)
g1_i[k] = (g1_i[k] + 1ull * weight_j * target[k]) % mod;
}
}
for (int i = 1; i <= n; ++i)
{
auto &g1_i = g1[i];
for (int j = 100; j; --j)
{
const int v = g1_i[100 + j];
g1_i[100 + j] = 0;
for (int k = j * 2; k <= 100; k += j)
UpdInc(g1_i[100 + k], v);
}
for (int j = 1; j <= 100; ++j)
g1_i[100 - j] = g1_i[100 + j];
}
g2[0][100] = 1;
for (int i = 1; i <= n; ++i)
{
const int iM2 = i - 2, end_j = min(iM2, siz_weight);
const auto &g2_iM1 = g2[i - 1];
auto &g2_i = g2[i];
memcpy(g2_i, g2_iM1 + 1, sizeof(int) * 200);
for (int j = 1; j <= 200; ++j)
UpdInc(g2_i[j], g2_iM1[j - 1]);
for (int j = 0; j <= end_j; ++j)
{
const int weight_j = weight[j];
const auto &target = g2[iM2 - j];
for (int k = 0; k <= 200; ++k)
g2_i[k] = (g2_i[k] + 1ull * weight_j * target[k]) % mod;
}
for (int j = 0; j <= 200; ++j)
{
int v = g2_i[j];
if (j != 100)
for (int k = 0; k <= iM2; ++k)
v = (v + 1ull * (g1[k][j] + g2[k][j]) * g2[iM2 - k][100]) % mod;
else
for (int k = 0; k <= iM2; ++k)
v = (v + 1ull * f[k] * g2[iM2 - k][100]) % mod;
g2_i[j] = v;
}
}
h[0][100] = 1;
for (int i = 1; i <= n; ++i)
{
const int iM2 = i - 2, end_j = min(iM2, siz_weight);
const auto &h_iM1 = h[i - 1];
auto &h_i = h[i];
memcpy(h_i + 1, h_iM1, sizeof(int) * 200);
for (int j = 1; j <= 200; ++j)
UpdInc(h_i[j - 1], h_iM1[j]);
for (int j = 0; j <= end_j; ++j)
{
const int weight_j = weight[j];
const auto &target = h[iM2 - j];
for (int k = 0; k <= 200; ++k)
h_i[k] = (h_i[k] + 1ull * weight_j * target[k]) % mod;
}
int v = h_i[100];
for (int j = 0; j <= iM2; ++j)
{
const auto &target = h[iM2 - j];
v = (v + 1ull * target[100] * f[j]) % mod;
for (int k = 0; k <= 200; ++k)
if (k != 100)
v = (v + 1ull * target[k] * (g1[j][k] + g2[j][k])) % mod;
}
h_i[100] = v;
}
const auto &h_n = h[n];
unsigned long long ans = 0;
for (int i = 0; i <= 200; ++i)
ans += h_n[i];
cout << ans % mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 0ms
memory: 3728kb
input:
10 9
output:
2320540
result:
ok single line: '2320540'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3728kb
input:
10 99
output:
38768740
result:
ok single line: '38768740'
Test #3:
score: 10
Accepted
time: 0ms
memory: 3732kb
input:
10 100
output:
38879818
result:
ok single line: '38879818'
Test #4:
score: 10
Accepted
time: 2ms
memory: 3788kb
input:
43 7
output:
217715835
result:
ok single line: '217715835'
Test #5:
score: 10
Accepted
time: 2ms
memory: 3744kb
input:
45 79
output:
287511486
result:
ok single line: '287511486'
Test #6:
score: 10
Accepted
time: 2ms
memory: 3860kb
input:
49 4317
output:
288237469
result:
ok single line: '288237469'
Test #7:
score: 10
Accepted
time: 7ms
memory: 3976kb
input:
100 8
output:
700817023
result:
ok single line: '700817023'
Test #8:
score: 10
Accepted
time: 7ms
memory: 3844kb
input:
98 8201
output:
655356172
result:
ok single line: '655356172'
Test #9:
score: 10
Accepted
time: 6ms
memory: 3836kb
input:
94 1777
output:
941271303
result:
ok single line: '941271303'
Test #10:
score: 10
Accepted
time: 7ms
memory: 3912kb
input:
100 9889
output:
461789726
result:
ok single line: '461789726'