QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#358817 | #8337. Counter Reset Problem | Kirill22# | WA | 44ms | 4392kb | C++23 | 4.3kb | 2024-03-20 01:20:25 | 2024-03-20 01:20:26 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
const int mod = (int) 1e9 + 9;
int add(int x, int y) {
return x + y >= mod ? x + y - mod : x + y;
}
int sub(int x, int y) {
return x - y < 0 ? x - y + mod : x - y;
}
int mul(int x, int y) {
return x * 1ll * y % mod;
}
int binpow(int x, int n) {
int res = 1;
while (n) {
if (n & 1) {
res = mul(res, x);
}
x = mul(x, x);
n >>= 1;
}
return res;
}
const int N = (int) 1e5;
int pw[N];
int check(int msk, int x) {
return msk % (1 << x) != 0;
}
vector<int> upd(vector<int> dp, char c) {
if (c == '0') {
return dp;
}
int uk = 0;
while (uk < dp.size() && dp[uk] > c - '0') uk++;
if (uk == dp.size()) dp.push_back(c - '0');
else dp[uk] = max(dp[uk], c - '0');
return dp;
}
int get(string s) {
vector<int> f = {10};
vector<vector<int>> qu = {f};
map<vector<int>, int> used;
used[f] = 0;
for (int i = 0; i < (int) qu.size(); i++) {
for (int x = 0; x < 10; x++) {
auto z = upd(qu[i], (char) '0' + x);
if (used.find(z) == used.end()) {
used[z] = (int) qu.size();
qu.push_back(z);
}
}
}
const int k = (int) qu.size(), m = (int) s.size();
vector<vector<int>> go(k, vector<int> (10));
for (int i = 0; i < k; i++) {
for (int x = 0; x < 10; x++) {
go[i][x] = used[upd(qu[i], (char) '0' + x)];
}
}
int ans = 0;
for (int x = 0; x <= s[0] - '0'; x++) {
if (x < s[0] - '0') {
ans = add(ans, mul(10 - x, pw[m - 1]));
} else {
ans = add(ans, 10 - x);
for (int j = 1; j < m; j++) {
ans = add(ans, mul(10 - x, mul(s[j] - '0', pw[m - j - 1])));
}
}
}
vector<int> dp(k), dp2(k);
int stk = 0;
for (int i = 0; i < m; i++) {
std::fill(dp2.begin(), dp2.end(), 0);
for (int x = 0; x < 10; x++) {
for (int msk = 0; msk < k; msk++) {
dp2[go[msk][x]] = add(dp2[go[msk][x]], dp[msk]);
}
if (x < s[i] - '0') {
dp2[go[stk][x]] = add(dp2[go[stk][x]], 1);
} else if (x == s[i] - '0') {
stk = go[stk][x];
}
}
dp = dp2;
}
dp[stk]++;
for (int i = 0; i < k; i++) {
if ((int) qu[i].size() <= 2 || !dp[i]) {
continue;
}
ans = add(ans, mul(10, mul((int) qu[i].size() - 2, dp[i])));
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
pw[0] = 1;
for (int i = 1; i < N; i++) {
pw[i] = mul(pw[i - 1], 10);
}
// get("10");
// return 0;
// cout << get("9") << " " << get("10") << " " << get("11") << endl;
// return 0;
// for (int n = 1; n < 25; n++) {
// cout << n << " " << get(to_string(n)) - get(to_string(n - 1)) << endl;
// }
// return 0;
int n;
string L, R;
cin >> n >> L >> R;
// {
// int ans = 0;
// for (int x = stoi(L); x <= stoi(R); x++) {
// string s = to_string(x);
// if (s[0] != '0') ans += 10 - (s[0] - '0');
// vector<int> dp = {(int) 1e9};
// for (auto c : s) {
// if (c == '0') continue;
// int uk = 0;
// while (uk < dp.size() && dp[uk] > c - '0') uk++;
// if (uk == dp.size()) dp.push_back(c - '0');
// else dp[uk] = max(dp[uk], c - '0');
// }
// ans += ((int) dp.size() - 2) * 10;
// }
// cout << ans;
// return 0;
// }
// while (!L.empty() && L[0] == '0') {
// L.erase(L.begin());
// }
// while (!R.empty() && R[0] == '0') {
// R.erase(R.begin());
// }
int ans = get(R);
if (count(L.begin(), L.end(), '0') != n) {
for (int i = (int) L.size() - 1; i >= 0; i--) {
if (L[i] == '0') {
L[i] = '9';
} else {
L[i]--;
break;
}
}
ans = sub(ans, get(L));
}
cout << ans;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 4392kb
input:
2 19 23
output:
51
result:
ok 1 number(s): "51"
Test #2:
score: 0
Accepted
time: 3ms
memory: 4096kb
input:
6 100084 518118
output:
9159739
result:
ok 1 number(s): "9159739"
Test #3:
score: 0
Accepted
time: 3ms
memory: 4152kb
input:
12 040139021316 234700825190
output:
771011551
result:
ok 1 number(s): "771011551"
Test #4:
score: 0
Accepted
time: 3ms
memory: 4092kb
input:
1 5 6
output:
9
result:
ok 1 number(s): "9"
Test #5:
score: 0
Accepted
time: 3ms
memory: 4096kb
input:
2 06 72
output:
609
result:
ok 1 number(s): "609"
Test #6:
score: 0
Accepted
time: 3ms
memory: 4128kb
input:
3 418 639
output:
2912
result:
ok 1 number(s): "2912"
Test #7:
score: 0
Accepted
time: 41ms
memory: 4156kb
input:
5000 0517031462295902016787205636287842713710486158285091634061538907131690102542613263904109051429895599547551249682345434244517372300211330243052548402051817254239088411128320032011447373157210750522722463984933692575118884942425236057310901139962840332684448050855646476051878413350560455871387882...
output:
107583434
result:
ok 1 number(s): "107583434"
Test #8:
score: 0
Accepted
time: 38ms
memory: 4108kb
input:
5000 2839631722409885676641854449409094340492285620998199901290315528351589154393629439187822315178094894928108915180727622985054953310653613329475433266861767377091508110388139487587162480394472451041742086595826537286229012805321959193382957731290351060584443229684181235109638118508206073343246746...
output:
675394398
result:
ok 1 number(s): "675394398"
Test #9:
score: 0
Accepted
time: 44ms
memory: 4112kb
input:
5000 0121086815228520611727091239718315691985426539178955693257347642954702438161323478758508490896602335048895013843711247876462745921412007803120100676220049634783076688779134708737789972863426435630047856085762842025741483042162463573248808646044510524282002015852558702184741741663627502716091539...
output:
578074633
result:
ok 1 number(s): "578074633"
Test #10:
score: 0
Accepted
time: 44ms
memory: 4172kb
input:
5000 4009315923866078525437170431271052539467314353326632440452295409898108927334934001515186676883568587509019024813648111170281871732854866326020722523420074725860024843129825137935119924032162976610499681775742229100481059217175250566980703955103400572138763397380102014106688956905053311588400020...
output:
819323161
result:
ok 1 number(s): "819323161"
Test #11:
score: -100
Wrong Answer
time: 22ms
memory: 4116kb
input:
5000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
603082573
result:
wrong answer 1st numbers differ - expected: '603082563', found: '603082573'