답안 #566596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566596 2022-05-22T12:46:49 Z Spade1 Palindrome-Free Numbers (BOI13_numbers) C++14
3.75 / 100
1 ms 360 KB
#include<bits/stdc++.h>
//#include "grader.h"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

ll dp[20][20][20];
ll mem[20];

ll cnt(ll cur) {
    ll ret = 0;
    string s = " " + to_string(cur);
    reverse(s.begin(), s.end());

    for (int i = s.size()-2; i >= 0; --i) {
        if (s[i]-'0' != 0) ret += mem[i];
        for (int j = 1; j < s[i]-'0'; ++j) {
            if (j == s[i+1]-'0') continue;
            for (int k1 = 0; k1 <= 10; ++k1) {
                for (int k2 = 0; k2 <= 10; ++k2) {
                    if (j == k1 || j == k2 || k1 == s[i+1]) continue;
                    ret += dp[i][k1][k2];
                }
            }
        }
    }

    return ret;
}

void solve() {
    ll a, b; cin >> a >> b;
    mem[1] = 10;
    mem[2] = 81;
    for (int i = 3; i <= 18; ++i) mem[i] = mem[i-1]*8;
    for (int i = 2; i <= 18; ++i) mem[i] += mem[i-1];
    for (int i = 0; i < 10; ++i) dp[1][i][10] = 1;
    for (int i = 2; i <= 18; ++i) {
        for (int j = 0; j < 10; ++j) {
            for (int k1 = 0; k1 <= 10; ++k1) {
                for (int k2 = 0; k2 <= 10; ++k2) {
                    if (j == k1 || j == k2) continue;
                    dp[i][j][k1] += dp[i-1][k1][k2];
                }
            }
        }
    }

    cout << cnt(b+1) - cnt(a) << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 1 ms 328 KB Output isn't correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 1 ms 324 KB Output isn't correct
11 Incorrect 1 ms 328 KB Output isn't correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Correct 1 ms 340 KB Output is correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 1 ms 324 KB Output isn't correct
20 Incorrect 1 ms 320 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 360 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 1 ms 320 KB Output isn't correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Incorrect 1 ms 324 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Incorrect 1 ms 340 KB Output isn't correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 1 ms 320 KB Output isn't correct
19 Incorrect 1 ms 340 KB Output isn't correct
20 Incorrect 1 ms 340 KB Output isn't correct
21 Incorrect 1 ms 340 KB Output isn't correct
22 Incorrect 1 ms 340 KB Output isn't correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Incorrect 1 ms 340 KB Output isn't correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Incorrect 1 ms 340 KB Output isn't correct
27 Incorrect 1 ms 340 KB Output isn't correct
28 Incorrect 1 ms 340 KB Output isn't correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Incorrect 1 ms 340 KB Output isn't correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Incorrect 1 ms 340 KB Output isn't correct
33 Incorrect 1 ms 340 KB Output isn't correct
34 Incorrect 1 ms 340 KB Output isn't correct
35 Incorrect 1 ms 320 KB Output isn't correct
36 Incorrect 1 ms 340 KB Output isn't correct
37 Incorrect 1 ms 340 KB Output isn't correct
38 Incorrect 1 ms 340 KB Output isn't correct
39 Incorrect 1 ms 324 KB Output isn't correct
40 Incorrect 1 ms 340 KB Output isn't correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Incorrect 1 ms 340 KB Output isn't correct
43 Incorrect 1 ms 340 KB Output isn't correct
44 Incorrect 1 ms 340 KB Output isn't correct
45 Incorrect 1 ms 340 KB Output isn't correct