Submission #77208

# Submission time Handle Problem Language Result Execution time Memory
77208 2018-09-24T01:43:41 Z Vinhspm Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
3 ms 748 KB
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define FOR(a, b, c) for(int a=b;a <= c;++a)
#define pb push_back
#define int long long

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int oo = 1e9;

int n;
int f[40][11][11][2];
void add(int &x, int y)  { x = (x + y); }
int solve(string maxn, int st) {
    //cout << st << '\n';
    memset(f, 0ll, sizeof f);
    f[0][0][0][0] = 1;
    FOR(i, 0, 18) FOR(las2, 0, 9) FOR(las1, 0, 9) {
        if(f[i][las2][las1][0]) {
            int h = maxn[i] - '0';
            FOR(t, 0, h)    if((i <= st) || (i == st + 1 && t != las1) || (t != las1 && t != las2))    {
                bool flag = 1;
                if(t == h) flag = false;
                add(f[i + 1][las1][t][flag], f[i][las2][las1][0]);
                //cout << f[i + 1][las1][t][flag] << ' ' << flag << '\n';
            }
        }
        if(f[i][las2][las1][1]) {
            //cout << i << ' ' << las2 << ' ' << las1 << ' ' << f[i][las2][las1][1] << '\n';
            FOR(t, 0, 9)    if((i <= st) || (i == st + 1 && t != las1) || (t != las1 && t != las2))    {
                add(f[i + 1][las1][t][1], f[i][las2][las1][1]);
            }
        }
    }
    // we need f[18][las1][las2][0]
    int sum = 0;
    FOR(i, 0, 9) FOR(j, 0, 9) add(sum, f[19][i][j][0]), add(sum, f[19][i][j][1]);
    return sum;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int l, r;   cin >> l >> r; l -= 1;
    string a = "", b = "";
    while(l > 0)    a = char(l % 10 + 48) + a, l /= 10;
    int sa = 19 - a.length();
    while(a.length() < 19) a = "0" + a;
    while(r > 0)    b = char(r % 10 + 48) + b, r /= 10;
    //cout << b << '\n';
    int sb = 19 - b.length();
    while(b.length() < 19) b = "0" + b;
    //cout << l << ' ' << sb << '\n';
    //cout << b << ' ' << sb << ' ' << a << ' ' << sa << '\n';
    if(l < 0) cout << solve(b, sb);
    else cout << solve(b, sb) - solve(a, sa);// :D
}
// 0 1000000000000000000
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 548 KB Output isn't correct
3 Correct 2 ms 548 KB Output is correct
4 Incorrect 2 ms 612 KB Output isn't correct
5 Incorrect 2 ms 612 KB Output isn't correct
6 Incorrect 2 ms 612 KB Output isn't correct
7 Incorrect 2 ms 612 KB Output isn't correct
8 Incorrect 2 ms 612 KB Output isn't correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
11 Correct 2 ms 612 KB Output is correct
12 Correct 2 ms 652 KB Output is correct
13 Correct 2 ms 652 KB Output is correct
14 Incorrect 2 ms 652 KB Output isn't correct
15 Incorrect 3 ms 652 KB Output isn't correct
16 Correct 2 ms 652 KB Output is correct
17 Correct 2 ms 652 KB Output is correct
18 Correct 2 ms 652 KB Output is correct
19 Correct 2 ms 652 KB Output is correct
20 Incorrect 2 ms 656 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 656 KB Output is correct
2 Correct 2 ms 656 KB Output is correct
3 Correct 2 ms 656 KB Output is correct
4 Correct 2 ms 656 KB Output is correct
5 Incorrect 2 ms 656 KB Output isn't correct
6 Correct 2 ms 656 KB Output is correct
7 Incorrect 2 ms 748 KB Output isn't correct
8 Incorrect 2 ms 748 KB Output isn't correct
9 Incorrect 2 ms 748 KB Output isn't correct
10 Incorrect 2 ms 748 KB Output isn't correct
11 Correct 2 ms 748 KB Output is correct
12 Incorrect 2 ms 748 KB Output isn't correct
13 Incorrect 2 ms 748 KB Output isn't correct
14 Incorrect 3 ms 748 KB Output isn't correct
15 Incorrect 2 ms 748 KB Output isn't correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 3 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 2 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 748 KB Output is correct
37 Correct 2 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 2 ms 748 KB Output is correct
40 Correct 2 ms 748 KB Output is correct
41 Correct 2 ms 748 KB Output is correct
42 Correct 2 ms 748 KB Output is correct
43 Correct 2 ms 748 KB Output is correct
44 Correct 2 ms 748 KB Output is correct
45 Correct 2 ms 748 KB Output is correct