Submission #93504

# Submission time Handle Problem Language Result Execution time Memory
93504 2019-01-09T02:52:27 Z luckyboy Palindrome-Free Numbers (BOI13_numbers) C++14
34.5833 / 100
2 ms 404 KB
/**GreenGrass**/
#include <bits/stdc++.h>
#define Ford(i,a,b) for(int i=a;i>=b;--i)
#define Forr(i,a,b) for(int i=a;i<b;++i)
#define For(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef long long ll;
ll dp[22][10][10], f[22][10], q[22], top;
void Pre(){
    For(i,1,9){
        f[1][i] = 1;
        f[2][i] = 9;
    }
    For(i,0,9)
        For(j,0,9)
            if(i!=j){
                dp[2][i][j]=1;
            }
    For(le,3,19){
        For(i,0,9){
            For(j,0,9){
                if(i==j) continue;
                For(k,0,9){
                    if(i==k||j==k) continue;
                    dp[le][i][j] += dp[le-1][j][k];
                }
                f[le][i] += dp[le][i][j];
            }
        }
    }
}
ll Calc(ll x){
    if(x<10) return x+1;
    top = 0;
    ll res = 10;
    while(x){
        q[++top] = x%10;
        x/=10;
    }
    For(i,2,top-1)
        For(j,1,9){
            res += f[i][j];
        }
    For(i,1,q[top]-1)
        res += f[top][i];
    Ford(i,top-1,1){
        For(j,0,q[i]-1){
            if(q[i+1]==j||(i<=top-2&&j==q[i+2])) continue;
            res += dp[i+1][q[i+1]][j];
        }
        if(q[i+1]==q[i]||(i<=top-2&&q[i]==q[i+2])) break;
        if(i) ++res;
    }
    return res;
}
void Setup(){
    ll a, b;
    cin >> a >> b;
    cout << Calc(b)-Calc(a-1);
}
int main(){
    ios_base::sync_with_stdio(NULL);
    cin .tie(NULL); cout .tie(NULL);
//    freopen("BlaBla.inp" , "r", stdin);
//    freopen("BlaBla.out", "w", stdout);
    Pre();
    Setup();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Incorrect 2 ms 404 KB Output isn't correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 2 ms 380 KB Output isn't correct
7 Incorrect 2 ms 380 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Incorrect 2 ms 376 KB Output isn't correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Incorrect 2 ms 376 KB Output isn't correct
20 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Incorrect 2 ms 376 KB Output isn't correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Correct 2 ms 376 KB Output is correct
16 Incorrect 2 ms 376 KB Output isn't correct
17 Correct 2 ms 368 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Incorrect 2 ms 376 KB Output isn't correct
22 Correct 2 ms 376 KB Output is correct
23 Incorrect 2 ms 376 KB Output isn't correct
24 Correct 2 ms 376 KB Output is correct
25 Incorrect 2 ms 348 KB Output isn't correct
26 Incorrect 2 ms 376 KB Output isn't correct
27 Incorrect 2 ms 376 KB Output isn't correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Incorrect 2 ms 376 KB Output isn't correct
32 Correct 2 ms 376 KB Output is correct
33 Incorrect 2 ms 376 KB Output isn't correct
34 Correct 2 ms 376 KB Output is correct
35 Incorrect 2 ms 376 KB Output isn't correct
36 Incorrect 2 ms 376 KB Output isn't correct
37 Incorrect 2 ms 376 KB Output isn't correct
38 Incorrect 2 ms 376 KB Output isn't correct
39 Incorrect 2 ms 376 KB Output isn't correct
40 Correct 2 ms 376 KB Output is correct
41 Incorrect 2 ms 376 KB Output isn't correct
42 Correct 2 ms 376 KB Output is correct
43 Incorrect 2 ms 376 KB Output isn't correct
44 Incorrect 2 ms 376 KB Output isn't correct
45 Incorrect 2 ms 376 KB Output isn't correct