답안 #92215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92215 2019-01-02T03:59:35 Z luckyboy Palindrome-Free Numbers (BOI13_numbers) C++14
27.9167 / 100
3 ms 380 KB
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int  i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int  i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 500005
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
long long dp[20][10][10],a,b,f[20][10];
int c[20],cnt;
void Prepare()
{
    FOR(i,0,9) f[1][i] = 1,f[2][i] = 9;
    FOR(i,0,9)
        FOR(j,0,9) dp[2][i][j] = (i != j);
    FOR(i,3,19)
        FOR(j,0,9)
            FOR(k,0,9)
            {
                if (j == k) continue;
                FOR(h,0,9)
                {
                    if (j == h) continue;
                    dp[i][j][k] += dp[i-1][k][h];
                }
                f[i][j] += dp[i][j][k];
            }
}
long long Calc(long long x)
{
    if (x < 10) return x + 1;
    long long res = 0;
    cnt = 0;
    while (x)
    {
        c[++cnt] = x % 10;
        x /= 10;
    }
    FOR(i,1,cnt - 1)
        FOR(j,1,9)
            res += f[i][j];
    FOR(i,1,c[cnt] - 1) res += f[cnt][i];
    FORD(i,cnt - 1,1)
    {
        FOR(j,1,c[i] - 1)
        {
            if (j == c[i+1] || (i + 2 <= cnt && c[i+2] == j)) continue;
            res += dp[i+1][c[i+1]][j];
        }
        if (c[i] == c[i+1] || (i + 2 <= cnt && c[i+2] == c[i])) break;
        if (i == 1) ++res;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    Prepare();
    cin >> a >> b;
    cout << Calc(b) - Calc(a-1);
    return 0;
}
# 결과 실행 시간 메모리 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 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 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 380 KB Output isn't correct
16 Correct 2 ms 376 KB Output is correct
17 Incorrect 2 ms 376 KB Output isn't correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 376 KB Output isn't correct
20 Incorrect 2 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 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 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 Incorrect 2 ms 376 KB Output isn't correct
16 Incorrect 2 ms 376 KB Output isn't correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 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 376 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 292 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 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 380 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