답안 #584144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584144 2022-06-26T23:27:20 Z Olympia Palindrome-Free Numbers (BOI13_numbers) C++17
19.5833 / 100
100 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome (int64_t i) {
    string s = to_string(i);
    bool fine = true;
    for (int j = 0; j < s.length(); j++) {
        if (j >= 1 && s[j] == s[j - 1]) {
            fine = false;
        }
        if (j >= 2 && s[j] == s[j - 2]) {
            fine = false;
        }
    }
    return fine;
}
int64_t powerOf10 (int x) {
    //pow(10, x)
    if (x == 1) {
        return 10;
    }
    int64_t tot = 81;
    for (int i = 0; i < x - 2; i++) {
        tot *= 8;
    }
    return tot + powerOf10(x - 1);
}
int64_t res (int64_t a, int64_t b) {
    int64_t ans = 0;
    for (int64_t i = a; i <= b; i++) {
        ans += isPalindrome(i);
    }
    return ans;
}
int64_t removeAllBut2 (int64_t x) {
    string s = to_string(x);
    for (int i = 2; i < s.length(); i++) {
        s[i] = '0';
    }
    return stoll(s);
}
int64_t query (int64_t a, int64_t b) {
    //cout << a << "<->" << b << '\n';
    if (b - a <= 1000) {
        return res(a, b);
    }
    if (a != 0) {
        return query(0, b) - query(0, a - 1);
    }
    if (a == b) {
        return a;
    }
    string s = to_string(b);
    int64_t tot = 0;
    int64_t c = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            for (int k = 0; k <= 9; k++) {
                if (i == j || j == k || i == k) continue;
                if (100 * i + 10 * j + k >= 100 * (s[0] - '0') + 10 * (s[1] - '0') + (s[2] - '0')) {
                    continue;
                }
                c++;
            }
        }
    }
    //reverse(b.begin(), b.end());
    tot += c * pow(8ll, (int)s.size() - 3);
    tot += powerOf10((int)s.length() - 1);
    reverse(s.begin(), s.end());
    s.pop_back();
    reverse(s.begin(), s.end());
    b = stoll(s);
    tot += query(removeAllBut2(b), b);
    return tot;
}
int main() {
    int64_t a, b;
    cin >> a >> b;
    cout << query(a, b) << '\n';
}

Compilation message

numbers.cpp: In function 'bool isPalindrome(int64_t)':
numbers.cpp:6:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for (int j = 0; j < s.length(); j++) {
      |                     ~~^~~~~~~~~~~~
numbers.cpp: In function 'int64_t removeAllBut2(int64_t)':
numbers.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 2; i < s.length(); i++) {
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 48 ms 276 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Incorrect 0 ms 212 KB Output isn't correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 49 ms 276 KB Output isn't correct
20 Incorrect 0 ms 212 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 68 ms 288 KB Output isn't correct
3 Incorrect 98 ms 276 KB Output isn't correct
4 Incorrect 90 ms 332 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Incorrect 0 ms 212 KB Output isn't correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Incorrect 0 ms 212 KB Output isn't correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Incorrect 99 ms 212 KB Output isn't correct
17 Incorrect 96 ms 276 KB Output isn't correct
18 Incorrect 91 ms 212 KB Output isn't correct
19 Incorrect 82 ms 280 KB Output isn't correct
20 Incorrect 73 ms 332 KB Output isn't correct
21 Incorrect 99 ms 212 KB Output isn't correct
22 Incorrect 35 ms 212 KB Output isn't correct
23 Incorrect 66 ms 212 KB Output isn't correct
24 Incorrect 82 ms 272 KB Output isn't correct
25 Incorrect 95 ms 212 KB Output isn't correct
26 Incorrect 96 ms 272 KB Output isn't correct
27 Incorrect 48 ms 272 KB Output isn't correct
28 Incorrect 72 ms 276 KB Output isn't correct
29 Incorrect 82 ms 272 KB Output isn't correct
30 Incorrect 95 ms 212 KB Output isn't correct
31 Incorrect 93 ms 276 KB Output isn't correct
32 Incorrect 94 ms 276 KB Output isn't correct
33 Incorrect 52 ms 212 KB Output isn't correct
34 Incorrect 92 ms 276 KB Output isn't correct
35 Incorrect 94 ms 276 KB Output isn't correct
36 Incorrect 89 ms 276 KB Output isn't correct
37 Incorrect 39 ms 272 KB Output isn't correct
38 Incorrect 83 ms 276 KB Output isn't correct
39 Incorrect 95 ms 212 KB Output isn't correct
40 Incorrect 87 ms 212 KB Output isn't correct
41 Incorrect 93 ms 276 KB Output isn't correct
42 Incorrect 100 ms 276 KB Output isn't correct
43 Incorrect 100 ms 272 KB Output isn't correct
44 Incorrect 87 ms 272 KB Output isn't correct
45 Incorrect 88 ms 212 KB Output isn't correct