Submission #1184403

#TimeUsernameProblemLanguageResultExecution timeMemory
1184403knhatdevPalindrome-Free Numbers (BOI13_numbers)C++20
72.50 / 100
0 ms328 KiB
#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define task ""
using namespace std;

const int N = 1e6 + 5, mod = 1e9 + 7;
int n, a[N], dp[20][2][15][15];

int cal(int pos, bool tight, int x, int y){
    if(pos > n) return 1;

    if(dp[pos][tight][x][y] != -1) return dp[pos][tight][x][y];
    int &res = dp[pos][tight][x][y];
    res = 0;
    for(int i = 0; i <= (tight ? a[pos] : 9); i++){
        if(i == y) continue;
        if(i == x) continue;
        res += cal(pos + 1, (tight & i == a[pos]), y, i);
    }
    return res;
}
int sol(int x){
    n = 0;
    if(x == 0) return 1;
    while(x){
        a[++n] = x % 10;
        x /= 10;
    }
    int l = 1, r = n;
    while(l < r){
        swap(a[l], a[r]);
        l++; r--;
    }
//    for(int i = 1; i <= n; i++) cout << a[i];
//    cout << '\n';
    memset(dp, -1, sizeof dp);
    return cal(1, 1, 10, 10);
}
main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen(task ".inp", "r")){
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int a, b;
    cin >> a >> b;
    if(a == 0){
        cout << sol(b);
        return 0;
    }
    cout << sol(b) - sol(a - 1);
}

Compilation message (stderr)

numbers.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main(){
      | ^~~~
numbers.cpp: In function 'int main()':
numbers.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...