답안 #488484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488484 2021-11-19T09:08:38 Z NintsiChkhaidze Palindrome-Free Numbers (BOI13_numbers) C++14
92.5 / 100
1000 ms 588 KB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll unsigned long long
#define int ll
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;
}
int G(int x){
    if (x < 0) return 0;
    memset(dp, -1, sizeof(dp));
    str = "";
    while(x > 0){
        str+=char((x%10)+'0');
        x/=10;
    }
    
    reverse(str.begin(),str.end());
    int l = str[0] - '0',ans = 1;
    for (int i = 1; i < l; i++)
        ans += get(i,i,1,1);
    ans += get(l,l,1,0);
 
    for (int i = 2; i <= str.size(); i++)
        for (int j=1;j<=9;j++)
            ans += get(j,j,i,1);
 
    return ans;
}
signed main (){
    ios_base::sync_with_stdio(0),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 'long long unsigned int get(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)':
numbers.cpp:14:34: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   14 |     if (dp[last2][last][len][sm] != -1)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Execution timed out 1089 ms 460 KB Time limit exceeded
6 Execution timed out 1044 ms 460 KB Time limit exceeded
7 Correct 1 ms 588 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Incorrect 1 ms 460 KB Output isn't correct
15 Execution timed out 1087 ms 460 KB Time limit exceeded
16 Correct 0 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Execution timed out 1094 ms 460 KB Time limit exceeded
19 Correct 1 ms 460 KB Output is correct
20 Correct 0 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 0 ms 460 KB Output is correct
21 Correct 0 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 0 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 0 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 0 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 0 ms 460 KB Output is correct
43 Correct 1 ms 516 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct