답안 #566663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566663 2022-05-22T14:41:12 Z Spade1 Palindrome-Free Numbers (BOI13_numbers) C++14
90 / 100
1 ms 340 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 = "a" + 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];
            }
        }
        if (s[i] == s[i+1]) break;
        if (s[i] == s[i+2]) break;
    }

    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 0 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is 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 0 ms 340 KB Output isn't correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 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 Correct 1 ms 340 KB Output is correct
15 Incorrect 0 ms 340 KB Output isn't correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Incorrect 0 ms 340 KB Output isn't correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct