답안 #633659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633659 2022-08-23T02:08:51 Z glome Palindrome-Free Numbers (BOI13_numbers) C++17
72.5 / 100
83 ms 384 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) {
    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:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i<s.size(); i++) {
      |                     ~^~~~~~~~~
numbers.cpp:20:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         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:30:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     if(pos == num.size()) {
      |        ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Correct 55 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 0 ms 340 KB Output isn't correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 1 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 0 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 2 ms 384 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 56 ms 352 KB Output is correct
20 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 340 KB Output is correct
2 Correct 79 ms 364 KB Output is correct
3 Correct 70 ms 352 KB Output is correct
4 Correct 76 ms 340 KB Output is correct
5 Incorrect 3 ms 340 KB Output isn't correct
6 Correct 5 ms 340 KB Output is correct
7 Incorrect 2 ms 340 KB Output isn't correct
8 Incorrect 2 ms 340 KB Output isn't correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 2 ms 340 KB Output isn't correct
11 Correct 6 ms 340 KB Output is correct
12 Incorrect 2 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 Correct 72 ms 356 KB Output is correct
17 Correct 83 ms 372 KB Output is correct
18 Correct 74 ms 340 KB Output is correct
19 Correct 76 ms 368 KB Output is correct
20 Correct 78 ms 340 KB Output is correct
21 Correct 70 ms 356 KB Output is correct
22 Correct 55 ms 340 KB Output is correct
23 Correct 79 ms 368 KB Output is correct
24 Correct 76 ms 340 KB Output is correct
25 Correct 77 ms 364 KB Output is correct
26 Correct 71 ms 352 KB Output is correct
27 Correct 75 ms 352 KB Output is correct
28 Correct 78 ms 352 KB Output is correct
29 Correct 71 ms 352 KB Output is correct
30 Correct 73 ms 340 KB Output is correct
31 Correct 70 ms 340 KB Output is correct
32 Correct 76 ms 356 KB Output is correct
33 Correct 56 ms 340 KB Output is correct
34 Correct 74 ms 356 KB Output is correct
35 Correct 75 ms 352 KB Output is correct
36 Correct 73 ms 372 KB Output is correct
37 Correct 62 ms 356 KB Output is correct
38 Correct 76 ms 340 KB Output is correct
39 Correct 77 ms 340 KB Output is correct
40 Correct 72 ms 352 KB Output is correct
41 Correct 70 ms 356 KB Output is correct
42 Correct 77 ms 364 KB Output is correct
43 Correct 76 ms 352 KB Output is correct
44 Correct 77 ms 356 KB Output is correct
45 Correct 79 ms 340 KB Output is correct