제출 #91982

#제출 시각아이디문제언어결과실행 시간메모리
91982karmaPalindrome-Free Numbers (BOI13_numbers)C++11
100 / 100
6 ms1144 KiB
#include<bits/stdc++.h> #define For(i, a, b) for(int i = a, _b = b; i <= _b; ++i) #define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i) #define FileName "test" #define ll long long #define ld long double #define ull unsigned long #define Print(x) cerr << #x << "is " << x << '\n'; #define pb push_back #define X first #define Y second //#define Karma using namespace std; template<typename T> inline void Cin(T &x) { char c; T sign = 1; x = 0; for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -1; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sign; } template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');} template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);} template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);} template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);} typedef pair<int, int> pii; typedef pair<ll, int> plli; ll f[20][10][10][20][2], a, b; string s; ll res; ll DP(int pos, int p1, int p2, int curpos, bool prefix) { if(pos >= s.size()) return 1; if(f[pos][p1][p2][curpos][prefix] != -1) return f[pos][p1][p2][curpos][prefix]; ll& res = f[pos][p1][p2][curpos][prefix]; res = 0; int lim = prefix? s[pos] - '0': 9; for(int i = 0; i <= lim; ++i) { if(curpos == 0) { if(i) res += DP(pos + 1, i, 0, 1, prefix && lim == i); else res += DP(pos + 1, 0, 0, 0, prefix && lim == i); } else if(i != p1) { if(curpos > 1 && i != p2) res += DP(pos + 1, i, p1, curpos + 1, prefix && lim == i); else if(curpos == 1) res += DP(pos + 1, i, p1, curpos + 1, prefix && lim == i); } } return res; } void Enter() { cin >> a >> b; res = 0; if(a == 0) ++ res; a = max(a - 1, 0ll); } void Solve() { stringstream cnv; cnv << b << '\n'; cnv >> s; memset(&f, -1, sizeof f); res += DP(0, 0, 0, 0, 1); cnv << a << '\n'; cnv >> s; memset(&f, -1, sizeof f); res -= DP(0, 0, 0, 0, 1); cout << res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef Karma freopen(FileName".inp", "r", stdin); freopen(FileName".out", "w", stdout); #endif // Karma Enter(); Solve(); return 0; }

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

numbers.cpp: In function 'long long int DP(int, int, int, int, bool)':
numbers.cpp:41:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(pos >= s.size()) return 1;
       ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...