Submission #207710

#TimeUsernameProblemLanguageResultExecution timeMemory
207710DodgeBallManPalindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
6 ms508 KiB
#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 (stderr)

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 ());
                                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...