제출 #1184422

#제출 시각아이디문제언어결과실행 시간메모리
1184422knhatdevPalindrome-Free Numbers (BOI13_numbers)C++20
100 / 100
3 ms1352 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[20], dp[20][2][15][15][15];

int cal(int pos, bool tight, int x, int y, int z, int sum){
    if(pos == 0) return 1;

    if(dp[pos][tight][x][y][z] != -1) return dp[pos][tight][x][y][z];
    int res = 0;
    for(int i = 0; i <= (tight ? a[pos] : 9); i++){
        if(i == z && sum > 0) continue;
        if(i == y && sum >= 10) continue;
        res += cal(pos - 1, (tight && (i == a[pos])), y, z, i, sum * 10 + i);
    }
    return dp[pos][tight][x][y][z] = res;
}
int sol(int x){
    n = 0;
    if(x == 0) return 1;
    while(x){
        a[++n] = x % 10;
        x /= 10;
    }
    memset(dp, -1, sizeof dp);
    return cal(n, 1, 10, 10, 10, 0);
}
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;
    cout << sol(b) - sol(a - 1);
}

컴파일 시 표준 에러 (stderr) 메시지

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