답안 #528315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528315 2022-02-19T22:23:45 Z CherryMagic Palindrome-Free Numbers (BOI13_numbers) C++14
15 / 100
1 ms 340 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int a,b;
vector<int> num;
long dp[22][10][10][2][2];

long call(int pos, int dig1, int dig2, int notpal, int f){
    if (pos == num.size()){
        if (dig1 != dig2 && notpal) return 1;
        else return 0;
    }

    if (dp[pos][dig1][dig2][notpal][f] != -1)
        return dp[pos][dig1][dig2][notpal][f];

    long res = 0;
    int lmt;
    if (f == 0){
        lmt = num[pos];
    }
    else{
        lmt = 9;
    }
    for (int dgt=0;dgt <= lmt; dgt++){
        int ndig1, ndig2, nnotpal = notpal, nf=f;
        if (f == 0 && dgt < lmt) nf = 1;
        if ((pos >=2 && dgt == dig1) || (pos>=1 && dgt == dig2)) nnotpal=0;
        if (pos >= 1) ndig1 = dig2;
        else ndig1 = 0;
        ndig2 = dgt;
        if (nnotpal) res += call(pos+1, ndig1, ndig2, nnotpal, nf);
    }

    return dp[pos][dig1][dig2][notpal][f] = res;
}

int solve(int a){
    num.clear();
    while (a > 0){
        num.push_back(a%10);
        a/=10;
    }
    reverse(num.begin(), num.end());
    memset(dp, -1, sizeof(dp));
    return call(0, 0, 0, 1, 0);
}

int main()
{
    cin >> a >> b;
    if (a == 0) cout << solve(b)<<endl;
    else cout << solve(b) - solve(a-1) << endl;
    return 0;
}

Compilation message

numbers.cpp: In function 'long int call(int, int, int, int, int)':
numbers.cpp:13:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     if (pos == num.size()){
      |         ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Incorrect 1 ms 296 KB Output isn't correct
5 Correct 1 ms 332 KB Output is correct
6 Incorrect 1 ms 296 KB Output isn't correct
7 Incorrect 0 ms 332 KB Output isn't correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Incorrect 1 ms 332 KB Output isn't correct
19 Incorrect 1 ms 296 KB Output isn't correct
20 Incorrect 0 ms 332 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 296 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 1 ms 300 KB Output isn't correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Correct 1 ms 300 KB Output is correct
7 Incorrect 0 ms 300 KB Output isn't correct
8 Incorrect 0 ms 332 KB Output isn't correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Incorrect 0 ms 332 KB Output isn't correct
11 Correct 1 ms 332 KB Output is correct
12 Incorrect 1 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Incorrect 1 ms 296 KB Output isn't correct
17 Incorrect 1 ms 332 KB Output isn't correct
18 Incorrect 1 ms 332 KB Output isn't correct
19 Incorrect 0 ms 332 KB Output isn't correct
20 Incorrect 0 ms 332 KB Output isn't correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Incorrect 1 ms 340 KB Output isn't correct
23 Incorrect 1 ms 332 KB Output isn't correct
24 Incorrect 0 ms 332 KB Output isn't correct
25 Incorrect 1 ms 332 KB Output isn't correct
26 Incorrect 1 ms 332 KB Output isn't correct
27 Incorrect 1 ms 292 KB Output isn't correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Incorrect 1 ms 332 KB Output isn't correct
30 Incorrect 1 ms 332 KB Output isn't correct
31 Incorrect 1 ms 292 KB Output isn't correct
32 Incorrect 1 ms 320 KB Output isn't correct
33 Incorrect 1 ms 332 KB Output isn't correct
34 Incorrect 1 ms 332 KB Output isn't correct
35 Incorrect 1 ms 300 KB Output isn't correct
36 Incorrect 1 ms 296 KB Output isn't correct
37 Incorrect 1 ms 332 KB Output isn't correct
38 Incorrect 1 ms 332 KB Output isn't correct
39 Incorrect 1 ms 332 KB Output isn't correct
40 Incorrect 1 ms 332 KB Output isn't correct
41 Incorrect 1 ms 332 KB Output isn't correct
42 Incorrect 1 ms 332 KB Output isn't correct
43 Incorrect 1 ms 332 KB Output isn't correct
44 Incorrect 1 ms 332 KB Output isn't correct
45 Incorrect 0 ms 332 KB Output isn't correct