Submission #633658

# Submission time Handle Problem Language Result Execution time Memory
633658 2022-08-23T02:07:20 Z glome Palindrome-Free Numbers (BOI13_numbers) C++17
0 / 100
84 ms 696 KB
#include <bits/stdc++.h>
 
using namespace std;

long long dp[19][200][2];

long long mod =1e9 + 7;

string num;

int pal(string n) {
    string y = n;
    reverse(y.begin(), y.end());
    return y == n;
}

int isok(string s) {
    cout << s << '\n';
    for (int i = 0; i<s.size(); i++) {
        string n = string(1, s[i]);
        for (int j = i + 1; j<s.size(); j++) {
            n += string(1, s[j]);
            if(pal(n)) return 0;
        }
    }
    return 1;
}

long long solve(int pos, long long cnt, int f,string s) {
    if(!isok(s)) return 0;
    if(pos == num.size()) {
        return isok(s);
    }
    if(dp[pos][cnt][f] != -1) return dp[pos][cnt][f];
    int lim = 9;
    if(!f) lim = num[pos] - '0'; 
    long long res = 0;
    for (int i = 0; i<=lim; i++) {
        res += solve(pos + 1, cnt + i, (i < lim || f), s + to_string(i));
    }
    return dp[pos][cnt][f] = res;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
    long long l, r;
    cin >> l >> r; 
    if(l > r) swap(l, r);
    l--;
    num = to_string(l);
    memset(dp, -1, sizeof(dp));
    long long a1 = solve(0, 0, 0, "");
    memset(dp, -1, sizeof(dp));
    num = to_string(r);
    cout << solve(0, 0, 0, "") - a1 << '\n';
    return 0;
}

Compilation message

numbers.cpp: In function 'int isok(std::string)':
numbers.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i<s.size(); i++) {
      |                     ~^~~~~~~~~
numbers.cpp:21:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for (int j = i + 1; j<s.size(); j++) {
      |                             ~^~~~~~~~~
numbers.cpp: In function 'long long int solve(int, long long int, int, std::string)':
numbers.cpp:31:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     if(pos == num.size()) {
      |        ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 58 ms 548 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Incorrect 1 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 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Incorrect 1 ms 340 KB Output isn't correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Incorrect 2 ms 324 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 2 ms 340 KB Output isn't correct
17 Incorrect 2 ms 340 KB Output isn't correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 57 ms 552 KB Output isn't correct
20 Incorrect 1 ms 340 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 416 KB Output isn't correct
2 Incorrect 79 ms 536 KB Output isn't correct
3 Incorrect 72 ms 616 KB Output isn't correct
4 Incorrect 79 ms 588 KB Output isn't correct
5 Incorrect 3 ms 340 KB Output isn't correct
6 Incorrect 6 ms 340 KB Output isn't correct
7 Incorrect 2 ms 340 KB Output isn't correct
8 Incorrect 2 ms 340 KB Output isn't correct
9 Incorrect 2 ms 340 KB Output isn't correct
10 Incorrect 2 ms 340 KB Output isn't correct
11 Incorrect 6 ms 340 KB Output isn't correct
12 Incorrect 3 ms 340 KB Output isn't correct
13 Incorrect 2 ms 340 KB Output isn't correct
14 Incorrect 3 ms 340 KB Output isn't correct
15 Incorrect 3 ms 340 KB Output isn't correct
16 Incorrect 72 ms 564 KB Output isn't correct
17 Incorrect 76 ms 524 KB Output isn't correct
18 Incorrect 75 ms 628 KB Output isn't correct
19 Incorrect 76 ms 596 KB Output isn't correct
20 Incorrect 81 ms 592 KB Output isn't correct
21 Incorrect 70 ms 568 KB Output isn't correct
22 Incorrect 55 ms 544 KB Output isn't correct
23 Incorrect 80 ms 600 KB Output isn't correct
24 Incorrect 77 ms 572 KB Output isn't correct
25 Incorrect 80 ms 696 KB Output isn't correct
26 Incorrect 74 ms 520 KB Output isn't correct
27 Incorrect 77 ms 636 KB Output isn't correct
28 Incorrect 78 ms 588 KB Output isn't correct
29 Incorrect 71 ms 620 KB Output isn't correct
30 Incorrect 75 ms 596 KB Output isn't correct
31 Incorrect 76 ms 612 KB Output isn't correct
32 Incorrect 75 ms 608 KB Output isn't correct
33 Incorrect 59 ms 520 KB Output isn't correct
34 Incorrect 80 ms 556 KB Output isn't correct
35 Incorrect 79 ms 564 KB Output isn't correct
36 Incorrect 75 ms 520 KB Output isn't correct
37 Incorrect 63 ms 540 KB Output isn't correct
38 Incorrect 79 ms 628 KB Output isn't correct
39 Incorrect 78 ms 584 KB Output isn't correct
40 Incorrect 73 ms 580 KB Output isn't correct
41 Incorrect 71 ms 520 KB Output isn't correct
42 Incorrect 80 ms 688 KB Output isn't correct
43 Incorrect 84 ms 520 KB Output isn't correct
44 Incorrect 80 ms 636 KB Output isn't correct
45 Incorrect 79 ms 592 KB Output isn't correct