답안 #207710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207710 2020-03-08T16:36:05 Z DodgeBallMan Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
6 ms 508 KB
#include <bits/stdc++.h>

using namespace std;

long long a, b, dp[20][15][15][2][2], ans;
char A[20];

long long solve( int pos = 0, int di1 = 10, int di2 = 10, bool m = false, bool s = false ) {
    if( !A[pos] ) return 1LL;
    long long &ret = dp[pos][di1][di2][m][s];
    if( ~ret ) return ret;
    ret = 0;
    int mx;
    if( m ) mx = 9;
    else mx = A[pos] - '0';
    for( int i = 0 ; i <= mx ; i++ ) {
        if( i == di1 || i == di2 ) continue;
        if( !i && !s ) ret += solve( pos + 1, 10, 10, true, false );
        else ret += solve( pos + 1, di2, i, m|( i < mx ), true );
    }
    return ret;
}

int main() 
{
	scanf("%lld %lld", &a, &b);
	memset( dp, -1LL, sizeof dp );
	sprintf( A, "%lld", b );
	ans = solve();
	if( a ) {
		memset( dp, -1LL, sizeof dp );
		sprintf( A, "%lld", a-1 );
		ans -= solve();
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
numbers.cpp:24:5: warning: '__builtin___sprintf_chk' may write a terminating nul past the end of the destination [-Wformat-overflow=]
 int main() 
     ^~~~
In file included from /usr/include/stdio.h:936:0,
                 from /usr/include/c++/7/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:46,
                 from numbers.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:34:43: note: '__builtin___sprintf_chk' output between 2 and 21 bytes into a destination of size 20
       __bos (__s), __fmt, __va_arg_pack ());
                                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 508 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 504 KB Output is correct
21 Correct 5 ms 504 KB Output is correct
22 Correct 5 ms 504 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 5 ms 504 KB Output is correct
35 Correct 5 ms 504 KB Output is correct
36 Correct 5 ms 504 KB Output is correct
37 Correct 5 ms 504 KB Output is correct
38 Correct 5 ms 504 KB Output is correct
39 Correct 5 ms 504 KB Output is correct
40 Correct 5 ms 504 KB Output is correct
41 Correct 5 ms 504 KB Output is correct
42 Correct 5 ms 504 KB Output is correct
43 Correct 5 ms 504 KB Output is correct
44 Correct 5 ms 504 KB Output is correct
45 Correct 5 ms 504 KB Output is correct