#define local
#ifndef local
#include ""
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 21;
const int oo = 1e18 + 7, mod = 1e9 + 7;
mt19937 rng(1);
int n;
int dp[19][100][3];
int cal(int x){
for(int i = 0; i <= 18; i++){
for(int j = 0; j < 100; j++){
for(int k = 0; k < 3; k++) dp[i][j][k] = 0;
}
}
if(x <= 99){
int ans = 0;
for(int i = 1; i <= x; i++){
if(!(i % 11)) continue;
ans++;
}
return ans;
}
int xx = x;
while(xx >= 100) xx /= 10;
//cout << xx << "\n";
for(int i = 0; i < 10; i++) dp[1][i][0] = 1;
for(int i = 10; i < 100; i++){
if(!(i % 11)) continue;
//cout << i << "\n";
int val;
if(i < xx) val = 0;
else if(i == xx) val = 1;
else val = 2;
dp[2][i][val] = 1;
}
xx = x;
int dig = 0;
vector<int> v;
while(xx){
v.pb(xx % 10);
dig++;
xx /= 10;
}
v.pb(-1);
reverse(v.begin(), v.end());
for(int i = 2; i < dig; i++){
for(int lst = 0; lst < 100; lst++){
for(int state = 0; state < 3; state++){
for(int nxt = 0; nxt < 10; nxt++){
if(nxt == lst%10) continue;
if(nxt == lst/10) continue;
int temp = (lst % 10) * 10 + nxt;
int nwstate = state;
if(nwstate == 1 && nxt > v[i + 1]) nwstate = 2;
if(nwstate == 1 && nxt < v[i + 1]) nwstate = 0;
//nwstate &= (nxt == v[i + 1]);
dp[i + 1][temp][nwstate] += dp[i][lst][state];
}
}
}
}
int tot = 0;
for(int temp = 1; temp <= dig; temp++){
for(int i = 0; i < 100; i++){
for(int j = 0; j < 3; j++){
if(temp == dig && j == 2) continue;
// cout << temp << " " << i << " " << j << " " << dp[temp][i][j] << "\n";
tot += dp[temp][i][j];
}
}
}
return tot;
}
#ifdef local
void process(){
int a, b;
cin >> a >> b;
// cout << cal(a - 1) << " " << cal(b) << "\n";
cout << cal(b) - cal(a - 1);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
process();
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |