답안 #102370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102370 2019-03-24T14:18:06 Z MoNsTeR_CuBe Palindrome-Free Numbers (BOI13_numbers) C++17
12.5 / 100
1000 ms 640 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

bool check(string a){
    for(int i = 0; i < (int)a.size()-1; i++){
        if(a[i] == a[i+1]) return false;
    }
    for(int i = 0; i < (int)a.size()-2; i++){
        if(a[i] == a[i+2]) return false;
    }
    return true;
}

string toString(int a){
    if(a == 0) return "0";
    string s = "";
    while(a){
        s = ((char)(a%10+'0'))+s;
        a/=10;
    }
    return s;
}

vector<int> v;

string a;
string b;

int memo[2][2][19][11][2][11];

int dp(bool isPal, bool canTakeAnything, int n, int last, bool isMini, int lastlast){
    if(n == a.size()){
        if(isPal) return 1;
        else return 0;
    }
    if(memo[isPal][canTakeAnything][n][last][isMini][lastlast] != -1) return memo[isPal][canTakeAnything][n][last][isMini][lastlast];
    memo[isPal][canTakeAnything][n][last][isMini][lastlast] = 0;
    if(canTakeAnything){
        int c = a[n]-'0'+1;
        for(int i = (isMini ? c : 1); i <= 10; i++){
            bool cond = false;
            if(isMini && i == c){
                cond = true;
            }
            if(i == last || i == lastlast){
                memo[isPal][canTakeAnything][n][last][isMini][lastlast] += dp(1,canTakeAnything,n+1,i,cond,last);
            }else{
                memo[isPal][canTakeAnything][n][last][isMini][lastlast] += dp(isPal, canTakeAnything, n+1, i,cond,last);
            }
        }
    }else{
        int c = a[n]-'0'+1;
        int d = b[n]-'0'+1;
        for(int i = (isMini ? c : 1); i<= d; i++){
            bool cond = false;
            if(isMini && i == c){
                cond = true;
            }
            if(i == last || i== lastlast){
                memo[isPal][canTakeAnything][n][last][isMini][lastlast] += dp(1, i < d, n+1,i,cond,last);
            }else{
                memo[isPal][canTakeAnything][n][last][isMini][lastlast] += dp(isPal, i < d, n+1,i, cond,last);
            }
        }
    }
    return memo[isPal][canTakeAnything][n][last][isMini][lastlast];
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int c, d;
    cin >> c >> d;
    string s = "";
    a = toString(c);
    b = toString(d);
    for(int i = 0; i < (int)(b.size()-a.size()); i++){
        s += '0';
    }
    a = s + a;
    int tot = (d-c+1);
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 19; k++){
                for(int l = 0; l <= 10; l++){
                    for(int m = 0; m < 2; m++){
                        for(int n = 0; n <= 10; n++){
                            memo[i][j][k][l][m][n] = -1;
                        }
                    }
                }
            }
        }
    }
    int tot1 = 0;
    for(int i = c; i <= d; i++){
        if(check(toString(i))) tot1++;
    }
    tot-=dp(0,0,0,0,1,0);
    if(c == 0) tot++;
    cout << tot << endl;
}

Compilation message

numbers.cpp: In function 'long long int dp(bool, bool, long long int, long long int, bool, long long int)':
numbers.cpp:34:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(n == a.size()){
        ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Incorrect 2 ms 512 KB Output isn't correct
3 Correct 40 ms 512 KB Output is correct
4 Incorrect 16 ms 512 KB Output isn't correct
5 Correct 2 ms 512 KB Output is correct
6 Incorrect 3 ms 512 KB Output isn't correct
7 Incorrect 3 ms 384 KB Output isn't correct
8 Incorrect 2 ms 512 KB Output isn't correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Incorrect 13 ms 512 KB Output isn't correct
15 Incorrect 12 ms 512 KB Output isn't correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Incorrect 2 ms 512 KB Output isn't correct
19 Correct 38 ms 512 KB Output is correct
20 Incorrect 15 ms 512 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 512 KB Time limit exceeded
2 Execution timed out 1076 ms 512 KB Time limit exceeded
3 Execution timed out 1057 ms 512 KB Time limit exceeded
4 Execution timed out 1060 ms 512 KB Time limit exceeded
5 Execution timed out 1077 ms 512 KB Time limit exceeded
6 Execution timed out 1080 ms 512 KB Time limit exceeded
7 Incorrect 451 ms 632 KB Output isn't correct
8 Incorrect 416 ms 632 KB Output isn't correct
9 Incorrect 618 ms 512 KB Output isn't correct
10 Incorrect 873 ms 520 KB Output isn't correct
11 Execution timed out 1079 ms 512 KB Time limit exceeded
12 Execution timed out 1080 ms 512 KB Time limit exceeded
13 Execution timed out 1074 ms 512 KB Time limit exceeded
14 Execution timed out 1070 ms 512 KB Time limit exceeded
15 Execution timed out 1068 ms 484 KB Time limit exceeded
16 Execution timed out 1070 ms 484 KB Time limit exceeded
17 Execution timed out 1078 ms 512 KB Time limit exceeded
18 Execution timed out 1061 ms 512 KB Time limit exceeded
19 Execution timed out 1074 ms 512 KB Time limit exceeded
20 Execution timed out 1069 ms 512 KB Time limit exceeded
21 Execution timed out 1072 ms 512 KB Time limit exceeded
22 Execution timed out 1076 ms 512 KB Time limit exceeded
23 Execution timed out 1071 ms 512 KB Time limit exceeded
24 Execution timed out 1070 ms 512 KB Time limit exceeded
25 Execution timed out 1078 ms 512 KB Time limit exceeded
26 Execution timed out 1059 ms 512 KB Time limit exceeded
27 Execution timed out 1066 ms 512 KB Time limit exceeded
28 Execution timed out 1080 ms 640 KB Time limit exceeded
29 Execution timed out 1058 ms 512 KB Time limit exceeded
30 Execution timed out 1057 ms 512 KB Time limit exceeded
31 Execution timed out 1078 ms 512 KB Time limit exceeded
32 Execution timed out 1078 ms 512 KB Time limit exceeded
33 Execution timed out 1054 ms 512 KB Time limit exceeded
34 Execution timed out 1056 ms 512 KB Time limit exceeded
35 Execution timed out 1082 ms 512 KB Time limit exceeded
36 Execution timed out 1073 ms 512 KB Time limit exceeded
37 Execution timed out 1080 ms 512 KB Time limit exceeded
38 Execution timed out 1059 ms 512 KB Time limit exceeded
39 Execution timed out 1051 ms 512 KB Time limit exceeded
40 Execution timed out 1076 ms 512 KB Time limit exceeded
41 Execution timed out 1060 ms 512 KB Time limit exceeded
42 Execution timed out 1063 ms 512 KB Time limit exceeded
43 Execution timed out 1052 ms 512 KB Time limit exceeded
44 Execution timed out 1063 ms 512 KB Time limit exceeded
45 Execution timed out 1068 ms 512 KB Time limit exceeded