Submission #91982

# Submission time Handle Problem Language Result Execution time Memory
91982 2018-12-31T18:07:29 Z karma Palindrome-Free Numbers (BOI13_numbers) C++11
100 / 100
6 ms 1144 KB
#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;
}

Compilation message

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 time Memory Grader output
1 Correct 6 ms 1016 KB Output is correct
2 Correct 2 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 4 ms 888 KB Output is correct
5 Correct 2 ms 888 KB Output is correct
6 Correct 2 ms 888 KB Output is correct
7 Correct 2 ms 888 KB Output is correct
8 Correct 2 ms 1016 KB Output is correct
9 Correct 2 ms 888 KB Output is correct
10 Correct 2 ms 1016 KB Output is correct
11 Correct 2 ms 1016 KB Output is correct
12 Correct 2 ms 1016 KB Output is correct
13 Correct 2 ms 1020 KB Output is correct
14 Correct 2 ms 892 KB Output is correct
15 Correct 2 ms 888 KB Output is correct
16 Correct 2 ms 888 KB Output is correct
17 Correct 2 ms 1016 KB Output is correct
18 Correct 2 ms 888 KB Output is correct
19 Correct 3 ms 888 KB Output is correct
20 Correct 2 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 888 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 888 KB Output is correct
4 Correct 4 ms 888 KB Output is correct
5 Correct 2 ms 888 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
7 Correct 2 ms 888 KB Output is correct
8 Correct 2 ms 1020 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 2 ms 1016 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 2 ms 888 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 2 ms 1016 KB Output is correct
16 Correct 4 ms 1016 KB Output is correct
17 Correct 4 ms 1016 KB Output is correct
18 Correct 4 ms 888 KB Output is correct
19 Correct 4 ms 888 KB Output is correct
20 Correct 4 ms 888 KB Output is correct
21 Correct 4 ms 888 KB Output is correct
22 Correct 4 ms 888 KB Output is correct
23 Correct 4 ms 888 KB Output is correct
24 Correct 4 ms 1016 KB Output is correct
25 Correct 4 ms 888 KB Output is correct
26 Correct 5 ms 1016 KB Output is correct
27 Correct 4 ms 888 KB Output is correct
28 Correct 4 ms 1016 KB Output is correct
29 Correct 4 ms 1016 KB Output is correct
30 Correct 4 ms 1016 KB Output is correct
31 Correct 4 ms 1016 KB Output is correct
32 Correct 4 ms 1016 KB Output is correct
33 Correct 4 ms 1016 KB Output is correct
34 Correct 4 ms 888 KB Output is correct
35 Correct 4 ms 1016 KB Output is correct
36 Correct 4 ms 1016 KB Output is correct
37 Correct 4 ms 888 KB Output is correct
38 Correct 4 ms 888 KB Output is correct
39 Correct 5 ms 1016 KB Output is correct
40 Correct 4 ms 1016 KB Output is correct
41 Correct 5 ms 988 KB Output is correct
42 Correct 4 ms 888 KB Output is correct
43 Correct 4 ms 1016 KB Output is correct
44 Correct 4 ms 1020 KB Output is correct
45 Correct 4 ms 1016 KB Output is correct