답안 #291108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291108 2020-09-04T16:54:09 Z ngotienhung Palindrome-Free Numbers (BOI13_numbers) C++14
38.75 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int     dp[10][10][20][2];
string  s;

int calc(int fi, int se, int len, int f){
    if(len >= s.length())
        return 1;

    if(dp[fi][se][len][f] != -1)
        return dp[fi][se][len][f];

    int res = 0;

    if(f){
        for(int i = 0; i <= 9; ++i){
            if(i != fi && i != se)
                res += calc(se, i, len + 1, true);
        }
    }
    else{
        int lim = s[len] - '0';

        for(int i = 0; i < lim; ++i){
            if(i != fi && i != se)
                res += calc(se, i, len + 1, true);
        }

        if(lim != fi && lim != se)
            res += calc(se, lim, len + 1, false);
    }

    return dp[fi][se][len][f] = res;
}

int solve(int a){
    stringstream ss;
    ss << a;
    s = ss.str();

    memset(dp, -1, sizeof(dp));

    int res = 0;

    bool tmp;
    for(int i = 1; i <= s[0] - '0'; ++i){
        if(i != s[0] - '0') tmp = true;
        else tmp = false;
        res += calc(i, i, 1, tmp);
    }

    for(int i = 2; i <= s.length(); ++i){
        for(int j = 1; j <= 9; ++j){
            res += calc(j, j, i, true);
        }
    }

    return res;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();

    int a,b;
    cin >> a >> b;

    int res = solve(b) - solve(a - 1);
    cout << res;

    return 0;
}

Compilation message

numbers.cpp: In function 'int calc(int, int, int, int)':
numbers.cpp:10:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     if(len >= s.length())
      |        ~~~~^~~~~~~~~~~~~
numbers.cpp: In function 'int solve(int)':
numbers.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 2; i <= s.length(); ++i){
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Incorrect 1 ms 384 KB Output isn't correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct
19 Incorrect 1 ms 384 KB Output isn't correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Incorrect 1 ms 384 KB Output isn't correct
17 Incorrect 1 ms 384 KB Output isn't correct
18 Incorrect 1 ms 384 KB Output isn't correct
19 Incorrect 1 ms 384 KB Output isn't correct
20 Incorrect 1 ms 384 KB Output isn't correct
21 Incorrect 1 ms 384 KB Output isn't correct
22 Incorrect 1 ms 384 KB Output isn't correct
23 Incorrect 1 ms 384 KB Output isn't correct
24 Incorrect 1 ms 384 KB Output isn't correct
25 Incorrect 1 ms 384 KB Output isn't correct
26 Incorrect 1 ms 384 KB Output isn't correct
27 Incorrect 1 ms 384 KB Output isn't correct
28 Incorrect 1 ms 384 KB Output isn't correct
29 Incorrect 1 ms 384 KB Output isn't correct
30 Incorrect 1 ms 384 KB Output isn't correct
31 Incorrect 1 ms 384 KB Output isn't correct
32 Incorrect 1 ms 384 KB Output isn't correct
33 Incorrect 1 ms 384 KB Output isn't correct
34 Incorrect 1 ms 384 KB Output isn't correct
35 Incorrect 1 ms 384 KB Output isn't correct
36 Incorrect 1 ms 384 KB Output isn't correct
37 Incorrect 1 ms 384 KB Output isn't correct
38 Incorrect 1 ms 384 KB Output isn't correct
39 Incorrect 1 ms 384 KB Output isn't correct
40 Incorrect 1 ms 384 KB Output isn't correct
41 Incorrect 1 ms 384 KB Output isn't correct
42 Incorrect 1 ms 384 KB Output isn't correct
43 Incorrect 1 ms 384 KB Output isn't correct
44 Incorrect 1 ms 384 KB Output isn't correct
45 Incorrect 1 ms 384 KB Output isn't correct