답안 #711929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711929 2023-03-17T16:58:22 Z lukameladze Palindrome-Free Numbers (BOI13_numbers) C++14
16.25 / 100
1 ms 340 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 328 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Incorrect 1 ms 328 KB Output isn't correct
20 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 1 ms 324 KB Output isn't correct
5 Incorrect 1 ms 328 KB Output isn't correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Correct 1 ms 328 KB Output is correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 328 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 1 ms 340 KB Output isn't correct
20 Incorrect 1 ms 340 KB Output isn't correct
21 Incorrect 1 ms 340 KB Output isn't correct
22 Incorrect 1 ms 340 KB Output isn't correct
23 Incorrect 1 ms 328 KB Output isn't correct
24 Incorrect 1 ms 340 KB Output isn't correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Incorrect 1 ms 340 KB Output isn't correct
27 Incorrect 1 ms 340 KB Output isn't correct
28 Incorrect 1 ms 336 KB Output isn't correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Incorrect 1 ms 340 KB Output isn't correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Incorrect 1 ms 340 KB Output isn't correct
33 Incorrect 1 ms 340 KB Output isn't correct
34 Incorrect 1 ms 340 KB Output isn't correct
35 Incorrect 1 ms 340 KB Output isn't correct
36 Incorrect 1 ms 340 KB Output isn't correct
37 Incorrect 1 ms 328 KB Output isn't correct
38 Incorrect 1 ms 340 KB Output isn't correct
39 Incorrect 1 ms 328 KB Output isn't correct
40 Incorrect 1 ms 328 KB Output isn't correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Incorrect 1 ms 328 KB Output isn't correct
43 Incorrect 1 ms 340 KB Output isn't correct
44 Incorrect 1 ms 340 KB Output isn't correct
45 Incorrect 1 ms 340 KB Output isn't correct