답안 #386139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386139 2021-04-05T18:21:35 Z ak2006 Palindrome-Free Numbers (BOI13_numbers) C++14
96.25 / 100
2 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll dp[20][11][11][2][2];
ll solve(vi&a,int i,int l1,int l2,int tight,int started)
{
    if (dp[i][l1][l2][tight][started] != 0)return dp[i][l1][l2][tight][started];
    if (i == (int)a.size())return 1;
    if (tight){
        for (int j = 0;j<a[i];j++){
            if (l1 == j || l2 == j)continue;
            if (started || j != 0)dp[i][l1][l2][1][started] += solve(a,i + 1,j,l1,0,1);
            else dp[i][l1][l2][1][0] += solve(a,i + 1,10,l1,0,0);
        }
        if (l1 != a[i] && l2 != a[i]){
            if (started || a[i] != 0)dp[i][l1][l2][1][started] += solve(a,i + 1,a[i],l1,1,1);
            else dp[i][l1][l2][1][0] += solve(a,i + 1,10,l1,1,0);
        }
    }
    else{
        for (int j = 0;j<=9;j++){
            if (l1 == j || l2 == j)continue;
            if (started || j != 0)dp[i][l1][l2][0][started] += solve(a,i + 1,j,l1,0,1);
            else dp[i][l1][l2][0][0] += solve(a,i + 1,10,l1,0,0);
        }
    }
    return dp[i][l1][l2][tight][started];
}
int main()
{
    ll a,b;
    cin>>a>>b;
    if (b == 0){cout<<1;return 0;}
    vi diga,digb;
    a--;
    while (a > 0){diga.pb(a%10);a/=10;}
    while (b > 0){digb.pb(b%10);b/=10;}
    if (!diga.empty())reverse(diga.begin(),diga.end());
    reverse(digb.begin(),digb.end());
    ll ans = 0;
    if (!diga.empty())ans = solve(diga,0,10,10,1,0);
    memset(dp,0,sizeof(dp));
    ans = -ans + solve(digb,0,10,10,1,0);
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 2 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct