제출 #57376

#제출 시각아이디문제언어결과실행 시간메모리
57376RezwanArefin01Palindrome-Free Numbers (BOI13_numbers)C++17
42.50 / 100
6 ms1252 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

ll dp[20][11][11][2][2]; 
char s[20]; 
int len; 

ll f(int pos, int a, int b, bool small, bool start) {
	if(pos == len) return 1; 
	ll &ret = dp[pos][a][b][small][start]; 
	if(~ret) return ret; 
	ret = 0; 
	int lim = small ? 9 : s[pos] - '0'; 

	for(int i = 0; i <= lim; i++) {
		if(i == a || i == b) continue; 
		if(!i && start) {
			ret += f(pos + 1, 10, 10, 1, 1); 
		} else {
			ret += f(pos + 1, b, i, small | i < lim, 0); 
		}
	} return ret; 
}

ll solve(int n) {
    sprintf(s, "%lld", n); 
    len = strlen(s); 
    memset(dp, -1, sizeof dp); 
    return f(0, 10, 10, 0, 1); 
}

int main(int argc, char const *argv[]) {
    ll a, b; 
    scanf("%lld %lld", &a, &b); 
    ll ans = solve(b); 
    if(a) ans -= solve(a - 1); 
    printf("%lld\n", ans); 
}

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

numbers.cpp: In function 'll f(int, int, int, bool, bool)':
numbers.cpp:23:38: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
    ret += f(pos + 1, b, i, small | i < lim, 0); 
                                    ~~^~~~~
numbers.cpp: In function 'll solve(int)':
numbers.cpp:29:25: warning: format '%lld' expects argument of type 'long long int', but argument 3 has type 'int' [-Wformat=]
     sprintf(s, "%lld", n); 
                         ^
numbers.cpp: In function 'int main(int, const char**)':
numbers.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld", &a, &b); 
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...