제출 #688336

#제출 시각아이디문제언어결과실행 시간메모리
688336stevancvPalindrome-Free Numbers (BOI13_numbers)C++14
98.33 / 100
1 ms384 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 800 + 2; const int inf = 1e9; ll dp[20][4]; /* dp[i][0] - is the same string possible dp[i][1] - only one position is used dp[i][2] - >= 2 is used */ ll F(string a) { if (a == "0") return 0; dp[0][0] = 1; dp[0][1] = a[0] - '1'; int x = a.size(); for (int i = 1; i < x; i++) { dp[i][0] = dp[i - 1][0]; if (a[i] == a[i - 1]) dp[i][0] = 0; if (i > 1 && a[i] == a[i - 2]) dp[i][0] = 0; dp[i][1] = 9; int k = a[i] - '0'; if (a[i - 1] < a[i]) k -= 1; if (i > 1 && a[i - 2] < a[i]) k -= 1; dp[i][2] = k * dp[i - 1][0] + 9 * dp[i - 1][1] + 8 * dp[i - 1][2]; } return dp[x - 1][0] + dp[x - 1][1] + dp[x - 1][2]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; ll ans = F(b) - F(a); int ok = 1; for (int i = 0; i < a.size(); i++) { if (i > 1 && a[i] == a[i - 1]) ok = 0; if (i > 2 && a[i] == a[i - 2]) ok = 0; } cout << ans + ok << en; return 0; }

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

numbers.cpp: In function 'int main()':
numbers.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i = 0; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...