답안 #486886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486886 2021-11-13T07:38:00 Z NintsiChkhaidze Palindrome-Free Numbers (BOI13_numbers) C++14
23.3333 / 100
1 ms 376 KB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
using namespace std;
 
string str;
int dp[15][15][25][5];
int get(int last2,int last,int len,int sm){
    if (len >= str.size()) return 1;
    if (dp[last2][last][len][sm] != -1) 
        return dp[last2][last][len][sm];
    
    int l = str[len] - '0',sum = 0;
    if (sm){
        for (int i = 0; i <= 9; i++){
            if (i != last && i != last2)
                sum += get(last,i,len + 1,1);
        }
    }
    else{
        for (int i = 0; i < l; i++){
            if (i != last && i != last2)
                sum += get(last,i,len + 1,1);
        }
        
        if (l != last && l != last2)
            sum += get(last,l,len + 1,0);    
    }
    return dp[last2][last][len][sm] = sum;
}
void clear(){
    for (int i = 0; i <= 9; i++)
        for (int j = 0; j <= 9; j++)
            for (int z = 0; z<=20; z++)
                dp[i][j][z][0] = dp[i][j][z][1] = -1;
}
int G(int x){
    if (x < 0) return 0;
    clear();
    str = "";
    while(x){
        str+=(x%10)+'0';
        x/=10;
    }
    
    reverse(str.begin(),str.end());
    int l = str[0] - '0',ans = 0;
    for (int i = 1; i < l; i++)
        ans += get(i,i,1,1);
    
    ans += get(l,l,1,0);
    return ans;
}
signed main (){
    ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL);
    ll a,b;
    cin>>a>>b;
    
    cout<<G(b) - G(a - 1)<<"\n";
}

Compilation message

numbers.cpp: In function 'int get(int, int, int, int)':
numbers.cpp:11:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     if (len >= str.size()) return 1;
      |         ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Incorrect 0 ms 316 KB Output isn't correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Incorrect 0 ms 332 KB Output isn't correct
8 Incorrect 0 ms 332 KB Output isn't correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Incorrect 0 ms 332 KB Output isn't correct
15 Incorrect 0 ms 332 KB Output isn't correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Incorrect 0 ms 332 KB Output isn't correct
20 Incorrect 0 ms 332 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Incorrect 0 ms 376 KB Output isn't correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Incorrect 1 ms 332 KB Output isn't correct
11 Correct 1 ms 332 KB Output is correct
12 Incorrect 1 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Incorrect 0 ms 332 KB Output isn't correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Incorrect 0 ms 332 KB Output isn't correct
18 Correct 0 ms 204 KB Output is correct
19 Incorrect 0 ms 332 KB Output isn't correct
20 Correct 0 ms 204 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Incorrect 1 ms 320 KB Output isn't correct
23 Incorrect 0 ms 204 KB Output isn't correct
24 Correct 0 ms 204 KB Output is correct
25 Incorrect 1 ms 320 KB Output isn't correct
26 Incorrect 0 ms 332 KB Output isn't correct
27 Incorrect 1 ms 204 KB Output isn't correct
28 Incorrect 0 ms 332 KB Output isn't correct
29 Correct 1 ms 204 KB Output is correct
30 Incorrect 1 ms 332 KB Output isn't correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Incorrect 1 ms 332 KB Output isn't correct
33 Incorrect 1 ms 332 KB Output isn't correct
34 Incorrect 0 ms 332 KB Output isn't correct
35 Incorrect 1 ms 332 KB Output isn't correct
36 Incorrect 1 ms 332 KB Output isn't correct
37 Incorrect 0 ms 332 KB Output isn't correct
38 Incorrect 1 ms 332 KB Output isn't correct
39 Incorrect 0 ms 332 KB Output isn't correct
40 Incorrect 1 ms 332 KB Output isn't correct
41 Incorrect 1 ms 332 KB Output isn't correct
42 Correct 0 ms 204 KB Output is correct
43 Incorrect 0 ms 332 KB Output isn't correct
44 Incorrect 0 ms 332 KB Output isn't correct
45 Incorrect 1 ms 332 KB Output isn't correct