Submission #922003

# Submission time Handle Problem Language Result Execution time Memory
922003 2024-02-04T16:38:12 Z dwuy Palindrome-Free Numbers (BOI13_numbers) C++14
96.25 / 100
1 ms 500 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(k == j) continue;
                if(i<len(s) && k == s[i] -'0') continue;
                res += dp[i][j][k];
            }
        }
        if(i<len(s) && s[i-1] == s[i]) break;
        if(i+1<len(s) && s[i-1] == s[i+1]) break;
    }
    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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is 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 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 352 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 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 360 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 500 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 348 KB Output is correct