답안 #711930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711930 2023-03-17T16:59:11 Z lukameladze Palindrome-Free Numbers (BOI13_numbers) C++14
73.75 / 100
2 ms 468 KB
# include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 3e5 + 5;
int t,n,a[N];
int dp[20][11][11][2][2][2];
int get(int x) {
    string s = to_string(x);
    memset(dp, 0, sizeof(dp));
    dp[0][10][10][0][0][0] = 1;
    s = "@" + s;
    for (int i = 1; i < (int)s.size(); i++) {
        for (int cur = 0; cur <= 9; cur++) {
            for (int pr_lst = 0; pr_lst <= 10; pr_lst++) {
                for (int lst = 0; lst <= 10; lst++) {
                    for (int less = 0; less <= 1; less++) {
                        for (int started = 0; started <= 1; started++) {
                            int new_less = 0;
                            
                            if (!less && cur > (int)(s[i] - '0')) continue;
                            if (less || cur < (int)(s[i] - '0')) {
                                new_less = 1;
                            } else new_less = 0;
                            int st = (started || (cur > 0));
                            if ((cur != pr_lst && cur != lst) || (!started))
                            dp[i][lst][cur][0][new_less][st] += dp[i - 1][pr_lst][lst][0][less][started], dp[i][lst][cur][1][new_less][st] += dp[i - 1][pr_lst][lst][1][less][started];
                            else
                            dp[i][lst][cur][1][new_less][st] += (dp[i - 1][pr_lst][lst][0][less][started] + dp[i - 1][pr_lst][lst][1][less][started]);
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = s.size() - 1; i < (int)s.size(); i++) {
        for (int pr_lst = 0; pr_lst <= 10; pr_lst++) {
            for (int lst = 0; lst <= 10; lst++) {
                for (int st = 0; st <= 1; st++) {
                    ans += dp[i][pr_lst][lst][0][0][st];
                    ans += dp[i][pr_lst][lst][0][1][st];
                }
            }
        }
    }
    return ans;
}
main() {
    std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int a, b;
    cin>>a>>b;
    cout<<get(b) - get(a - 1)<<"\n";
}

Compilation message

numbers.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Correct 1 ms 468 KB Output is correct
4 Incorrect 1 ms 468 KB Output isn't correct
5 Correct 1 ms 468 KB Output is correct
6 Incorrect 1 ms 468 KB Output isn't correct
7 Incorrect 1 ms 468 KB Output isn't correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Incorrect 1 ms 468 KB Output isn't correct
15 Incorrect 1 ms 468 KB Output isn't correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Incorrect 1 ms 468 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Incorrect 1 ms 468 KB Output isn't correct
6 Correct 1 ms 468 KB Output is correct
7 Incorrect 1 ms 468 KB Output isn't correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Incorrect 1 ms 468 KB Output isn't correct
10 Incorrect 1 ms 468 KB Output isn't correct
11 Correct 1 ms 348 KB Output is correct
12 Incorrect 1 ms 468 KB Output isn't correct
13 Incorrect 1 ms 468 KB Output isn't correct
14 Incorrect 1 ms 468 KB Output isn't correct
15 Incorrect 1 ms 468 KB Output isn't correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct