제출 #35792

#제출 시각아이디문제언어결과실행 시간메모리
35792funcsrPalindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
0 ms2268 KiB
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 long long A, B; long long dp[20][10][10][3][2]; long long solve(string X) { rep(i, X.size()+1) rep(j, 10) rep(k, 10) rep(l, 3) rep(r, 2) dp[i][j][k][l][r] = 0; dp[0][0][0][0][0] = 1; rep(i, X.size()) { int ud = X[i]-'0'; rep(j, 10) { rep(k, 10) { rep(s, 3) { rep(r, 2) { if (dp[i][j][k][s][r] == 0) continue; rep(next, 10) { if (s == 1 && k == next) continue; if (s == 2 && (k == next || j == next)) continue; if (r == 0 && next > ud) continue; int ns = s; if (ns == 0) { if (next) ns++; } else if (ns == 1) ns++; dp[i+1][k][next][ns][r|(next<ud)] += dp[i][j][k][s][r]; } } } } } } long long s = 0; rep(i, 10) rep(j, 10) rep(k, 3) rep(r, 2) s += dp[X.size()][i][j][k][r]; return s; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> A >> B; long long s = solve(to_string(B)); if (A > 0) s -= solve(to_string(A-1)); cout << s << "\n"; return 0; }

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

numbers.cpp: In function 'long long int solve(std::__cxx11::string)':
numbers.cpp:17:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
numbers.cpp:30:3: note: in expansion of macro 'rep'
   rep(i, X.size()+1) rep(j, 10) rep(k, 10) rep(l, 3) rep(r, 2) dp[i][j][k][l][r] = 0;
   ^
numbers.cpp:17:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
numbers.cpp:32:3: note: in expansion of macro 'rep'
   rep(i, X.size()) {
   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...