이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long int lli;
const lli maxn = 20;
lli memo[maxn][12][12][2][2];
string A[2];
inline bool ispal(lli x, lli y, lli z) { return ((y == z) || (x == z)); }
lli DP(lli idx, lli prev, lli pprev, lli less, lli type)
{
if(idx == lli(A[type].size())) return 1;
else if(memo[idx][prev][pprev][less][type] != -1) return memo[idx][prev][pprev][less][type];
else
{
lli res = 0, val = (less?9:lli(A[type][idx]-'0'));
for(lli i = 0;i <= val;i++)
{
if(ispal(pprev, prev, i)) continue;
res += DP(idx+1, i, prev, max(less, lli(i < val)), type);
}
return memo[idx][prev][pprev][less][type] = res;
}
}
int main(void)
{
lli a, b;
scanf("%lld%lld", &a, &b);
A[0] = to_string(b), A[1] = to_string(a-1);
for(lli i = 0;i < maxn;i++)
{
for(lli j = 0;j < 11;j++)
{
for(lli k = 0;k < 11;k++)
{
for(lli l = 0;l < 2;l++) memo[i][j][k][l][0] = memo[i][j][k][l][1] = -1;
}
}
}
lli res = DP(0, 10, 10, 0, 0)-DP(0, 10, 10, 0, 1);
printf("%lld\n", res);
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp: In function 'int main()':
numbers.cpp:34:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &a, &b);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |