답안 #637454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637454 2022-09-01T20:25:50 Z glome Palindrome-Free Numbers (BOI13_numbers) C++17
16.25 / 100
1000 ms 388 KB
#include <bits/stdc++.h>
 
using namespace std;

long long dp[19][11][11][2][2];

string num;

long long rec(int pos, int prev1, int prev2, int f, int prev) {
    if(pos == num.size()) return 1;

    
    int LIM = 9;
    if(!f) LIM = num[pos] - '0';
    
    long long res = 0;

    for (int i = 0; i<=LIM; i++) {
        if(prev) {
            if(i == prev2 || i == prev1) continue;
            res += rec(pos + 1, i, prev1, (f || i < LIM), prev);
        }
        else {
            res += rec(pos + 1, i, prev1, (f || i < LIM), (i != 0));
        }
    }
    return dp[pos][prev1][prev2][f][prev] = res;


}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a,b, k = 0;
    cin >> a >> b;
    if(a == 0) k += 1;
    memset(dp, -1, sizeof(dp)); num = to_string(b);
    b = rec(0, 10, 10, 0, 0);
    a = max(a-1, 0LL);
    memset(dp, -1, sizeof(dp)); num = to_string(a);

    cout << b - rec(0, 10, 10, 0, 0) + k << '\n';
    return 0;
}

Compilation message

numbers.cpp: In function 'long long int rec(int, int, int, int, int)':
numbers.cpp:10:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     if(pos == num.size()) return 1;
      |        ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Execution timed out 1093 ms 340 KB Time limit exceeded
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 0 ms 340 KB Output is correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 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 5 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Execution timed out 1095 ms 340 KB Time limit exceeded
20 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 368 KB Output is correct
2 Execution timed out 1096 ms 340 KB Time limit exceeded
3 Execution timed out 1097 ms 340 KB Time limit exceeded
4 Execution timed out 1096 ms 340 KB Time limit exceeded
5 Incorrect 142 ms 340 KB Output isn't correct
6 Correct 484 ms 368 KB Output is correct
7 Incorrect 10 ms 340 KB Output isn't correct
8 Incorrect 7 ms 340 KB Output isn't correct
9 Incorrect 11 ms 384 KB Output isn't correct
10 Incorrect 14 ms 340 KB Output isn't correct
11 Correct 368 ms 368 KB Output is correct
12 Incorrect 83 ms 368 KB Output isn't correct
13 Incorrect 23 ms 388 KB Output isn't correct
14 Incorrect 139 ms 364 KB Output isn't correct
15 Incorrect 162 ms 340 KB Output isn't correct
16 Execution timed out 1088 ms 340 KB Time limit exceeded
17 Execution timed out 1038 ms 340 KB Time limit exceeded
18 Execution timed out 1073 ms 340 KB Time limit exceeded
19 Execution timed out 1094 ms 340 KB Time limit exceeded
20 Execution timed out 1094 ms 340 KB Time limit exceeded
21 Execution timed out 1097 ms 340 KB Time limit exceeded
22 Execution timed out 1096 ms 340 KB Time limit exceeded
23 Execution timed out 1078 ms 340 KB Time limit exceeded
24 Execution timed out 1043 ms 340 KB Time limit exceeded
25 Execution timed out 1100 ms 340 KB Time limit exceeded
26 Execution timed out 1100 ms 340 KB Time limit exceeded
27 Execution timed out 1087 ms 340 KB Time limit exceeded
28 Execution timed out 1099 ms 340 KB Time limit exceeded
29 Execution timed out 1092 ms 340 KB Time limit exceeded
30 Execution timed out 1099 ms 340 KB Time limit exceeded
31 Execution timed out 1051 ms 340 KB Time limit exceeded
32 Execution timed out 1086 ms 340 KB Time limit exceeded
33 Execution timed out 1092 ms 340 KB Time limit exceeded
34 Execution timed out 1099 ms 340 KB Time limit exceeded
35 Execution timed out 1096 ms 340 KB Time limit exceeded
36 Execution timed out 1088 ms 340 KB Time limit exceeded
37 Execution timed out 1081 ms 340 KB Time limit exceeded
38 Execution timed out 1086 ms 340 KB Time limit exceeded
39 Execution timed out 1087 ms 340 KB Time limit exceeded
40 Execution timed out 1078 ms 340 KB Time limit exceeded
41 Execution timed out 1053 ms 340 KB Time limit exceeded
42 Execution timed out 1095 ms 340 KB Time limit exceeded
43 Execution timed out 1091 ms 340 KB Time limit exceeded
44 Execution timed out 1098 ms 340 KB Time limit exceeded
45 Execution timed out 1085 ms 340 KB Time limit exceeded