답안 #132845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132845 2019-07-19T18:10:31 Z muradeyn Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
3 ms 504 KB
/* Murad Eynizade */

#include <bits/stdc++.h>
#define intt long long
#define fyck ios_base::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
//#define endl '\n'

using namespace std;

int len;

intt a , b;

intt dp[20][11][11][2];

string s;

intt solve(int i,int d1,int d2,int f) {
    //cout<<i<<" "<<d1<<" "<<d2<<" "<<f<<endl;
    if (dp[i][d1][d2][f] != -1)return dp[i][d1][d2][f];
    if (i == len) return dp[i][d1][d2][f] = f;
    intt ret = 0;
    int til;
    if (f) til = 9;
    else til = s[i] - '0';
    for (int in = 0;in<=til;in++) {
        if ((d1 != 10 && in == d1) || (d2 != 10 && in == d2) )continue;
        if (in == 0 && d2 == 10 && i != len - 1)continue;
        int nf = f;
        nf |= (in < s[i] - '0');
        nf |= (in == 10);
        ret += solve(i + 1 , d2 , in , nf);
    }
    if (d2 == 10 && i != len - 1) ret += solve(i + 1 , d2 , d2 , 1);
    return dp[i][d1][d2][f] = ret;
}

intt get(intt x) {
    memset(dp , -1 , sizeof(dp));
    s = "";
    len = 0;
    while (x) {
        s += x % 10 + '0';
        x /= 10;
        len++;
    }
    reverse(s.begin(),s.end());
    return solve(0 , 10 , 10 , 0);
}

int main() {
    fyck
    cin>>a>>b;
    cout<<get(b + 1) - get(a)<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is 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 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is 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 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 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 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 504 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 380 KB Output is correct
45 Correct 2 ms 376 KB Output is correct