Submission #921994

# Submission time Handle Problem Language Result Execution time Memory
921994 2024-02-04T16:05:58 Z dwuy Palindrome-Free Numbers (BOI13_numbers) C++14
21.25 / 100
1 ms 348 KB
#include <bits/stdc++.h>

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK "test"
#define int long long

using namespace std;

typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;

const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;


int dp[20][10][11];

string ts(int x){
    stringstream ss; ss << x;
    string res; ss >> res;
    return res;
}

bool ok(string s){
    for(int i=0; i+1<len(s); i++) if(s[i] == s[i+1]) return 0;
    for(int i=1; i+1<len(s); i++) if(s[i+1] == s[i-1]) return 0;
    return 1;
}

int calc(int x){
    if(x == 0) return 0;
    memset(dp, 0, sizeof dp);
    string s = ts(x);
    reverse(s.begin(), s.end());
    for(int j=0; j<=9; j++) dp[1][j][10] = 1;
    for(int i=2; i<=len(s); i++){
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                if(j == k) continue;
                for(int f=0; f<=10; f++){
                    if(j == f) continue;
                    dp[i][j][k] += dp[i-1][k][f];
                }
            }
        }
    }
    int res = 0;
    for(int i=1; i<len(s); i++){
        for(int j=1; j<=9; j++){
            for(int k=0; k<=10; k++){
                res += dp[i][j][k];
            }
        }
    }
    for(int i=len(s); i>0 ; i--){
        for(int j=(i==len(s)? 1 : 0); j<s[i-1]-'0'; j++){
            if(i<len(s) && j == s[i] - '0') continue;
            if(i+1<len(s) && j == s[i+1] - '0') continue;
            for(int k=0; k<=10; k++){
                if(i<len(s) && k == s[i] -'0') continue;
                res += dp[i][j][k];
            }
        }
    }
    return res + ok(s);
}

int32_t main(){
    fastIO;
    //file(TASK);

    int l, r;
    cin >> l >> r;
    cout << calc(r) - calc(l-1);

    return 0;
}




# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Correct 0 ms 348 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 1 ms 344 KB Output isn't correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 1 ms 348 KB Output isn't correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Correct 0 ms 344 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Incorrect 0 ms 344 KB Output isn't correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Incorrect 0 ms 348 KB Output isn't correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Incorrect 0 ms 348 KB Output isn't correct
23 Incorrect 0 ms 348 KB Output isn't correct
24 Incorrect 0 ms 348 KB Output isn't correct
25 Incorrect 0 ms 348 KB Output isn't correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Incorrect 0 ms 348 KB Output isn't correct
28 Incorrect 0 ms 348 KB Output isn't correct
29 Incorrect 0 ms 348 KB Output isn't correct
30 Incorrect 0 ms 348 KB Output isn't correct
31 Incorrect 0 ms 348 KB Output isn't correct
32 Incorrect 0 ms 348 KB Output isn't correct
33 Incorrect 0 ms 348 KB Output isn't correct
34 Incorrect 0 ms 348 KB Output isn't correct
35 Incorrect 0 ms 348 KB Output isn't correct
36 Incorrect 0 ms 344 KB Output isn't correct
37 Incorrect 1 ms 344 KB Output isn't correct
38 Incorrect 0 ms 348 KB Output isn't correct
39 Incorrect 0 ms 348 KB Output isn't correct
40 Incorrect 0 ms 348 KB Output isn't correct
41 Incorrect 0 ms 348 KB Output isn't correct
42 Incorrect 1 ms 348 KB Output isn't correct
43 Incorrect 0 ms 348 KB Output isn't correct
44 Incorrect 0 ms 348 KB Output isn't correct
45 Incorrect 0 ms 348 KB Output isn't correct