답안 #566656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566656 2022-05-22T14:26:44 Z Spade1 Palindrome-Free Numbers (BOI13_numbers) C++14
13.75 / 100
1 ms 384 KB
#include<bits/stdc++.h>
//#include "grader.h"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

ll dp[20][20][20];
ll mem[20];

ll cnt(ll cur) {
    ll ret = 0;
    string s = " " + to_string(cur);
    reverse(s.begin(), s.end());

    for (int i = s.size()-2; i >= 0; --i) {
        if (i==s.size()-2) ret += mem[i];
        for (int j = (i==s.size()-2); j < s[i]-'0'; ++j) {
            if (j == s[i+1]-'0' || j == s[i+2]-'0') continue;
            for (int k1 = 0; k1 <= 10; ++k1) {
                if (k1 == s[i+1]-'0' || j == k1) continue;
                ret += dp[i+1][j][k1];
            }
        }
    }

    return ret;
}

void solve() {
    ll a, b; cin >> a >> b;
    mem[1] = 10;
    mem[2] = 81;
    for (int i = 3; i <= 18; ++i) mem[i] = mem[i-1]*8;
    for (int i = 2; i <= 18; ++i) mem[i] += mem[i-1];
    for (int i = 0; i < 10; ++i) dp[1][i][10] = 1;
    for (int i = 2; i <= 18; ++i) {
        for (int j = 0; j < 10; ++j) {
            for (int k1 = 0; k1 <= 10; ++k1) {
                for (int k2 = 0; k2 <= 10; ++k2) {
                    if (j == k1 || j == k2) continue;
                    dp[i][j][k1] += dp[i-1][k1][k2];
                }
            }
        }
    }

    cout << cnt(b+1) - cnt(a)<< '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Compilation message

numbers.cpp: In function 'long long int cnt(long long int)':
numbers.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         if (i==s.size()-2) ret += mem[i];
      |             ~^~~~~~~~~~~~
numbers.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int j = (i==s.size()-2); j < s[i]-'0'; ++j) {
      |                       ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Correct 0 ms 340 KB Output is 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 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Correct 1 ms 340 KB Output is correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Correct 0 ms 340 KB Output is correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 0 ms 340 KB Output isn't correct
20 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 1 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 Correct 1 ms 340 KB Output is correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Correct 0 ms 340 KB Output is correct
15 Incorrect 0 ms 340 KB Output isn't correct
16 Incorrect 0 ms 340 KB Output isn't correct
17 Incorrect 0 ms 340 KB Output isn't correct
18 Incorrect 0 ms 340 KB Output isn't correct
19 Incorrect 0 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 0 ms 340 KB Output isn't correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Incorrect 0 ms 340 KB Output isn't correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Incorrect 0 ms 340 KB Output isn't correct
27 Incorrect 0 ms 340 KB Output isn't correct
28 Incorrect 0 ms 340 KB Output isn't correct
29 Incorrect 0 ms 340 KB Output isn't correct
30 Incorrect 0 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 0 ms 340 KB Output isn't correct
34 Incorrect 0 ms 340 KB Output isn't correct
35 Incorrect 0 ms 340 KB Output isn't correct
36 Incorrect 0 ms 340 KB Output isn't correct
37 Incorrect 0 ms 340 KB Output isn't correct
38 Incorrect 0 ms 340 KB Output isn't correct
39 Incorrect 1 ms 340 KB Output isn't correct
40 Incorrect 0 ms 340 KB Output isn't correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Incorrect 1 ms 340 KB Output isn't correct
43 Incorrect 1 ms 340 KB Output isn't correct
44 Incorrect 0 ms 340 KB Output isn't correct
45 Incorrect 1 ms 340 KB Output isn't correct