Submission #442122

# Submission time Handle Problem Language Result Execution time Memory
442122 2021-07-07T07:42:30 Z keertan Palindrome-Free Numbers (BOI13_numbers) C++17
66.6667 / 100
1 ms 384 KB
#include<bits/stdc++.h>
using namespace std;
//#define int int64_t
const int64_t mod=1000000007;
namespace personal{
    template<typename T>
    int32_t sz(T x){return x.size();}
    void equal(string &s,string &s1){
        string ex(sz(s1)-sz(s),'0');
        s=ex+s;
    }
    void equal(string &s,int x){
        string ex(x-sz(s),'0');
        s=ex+s;
    }
    void minus(string &s){
        int32_t n=sz(s);
        n--;
        while(n+1 && s[n]=='0'){s[n]='9',n--;}
        s[n]--;       
    }
    void base_converter(int base,string &s,int x){
        s.clear();
        while(x){
            s+=(char)((x%base)+'0');
            x/=base;
        }
        reverse(s.begin(),s.end());
        //cerr<<s<<"\n";
    }
};
const int N=20,bl=2;
int cache[20][11][11][bl][bl][bl];
int n;
string s,s1;
int dp(int pos,int prv,int prv1,bool bigA,bool smallB,bool nonzero){
     //cerr<<pos<<" "<<prv<<" "<<bigA<<" "<<smallB<<" "<<n<<"\n";
    if (n==pos){
        //cout<<p<<"\n";
        return 1;
    }
    int &ans=cache[pos][prv1+1][prv+1][bigA][smallB][nonzero];
    if (ans!=-1){return ans;}
    ans=0;
    for (int i=0;i<10;i++){
        //cerr<<pos<<" "<<prv<<" "<<bigA<<" "<<smallB<<"\n";
        if (!bigA && i<(s[pos]-'0')){continue;}
        if (!smallB && i>(s1[pos]-'0')){continue;}
        
        if (!nonzero && !i){
            ans+=dp(pos+1,prv,prv1,bigA||(i>(s[pos]-'0')),smallB||(i<(s1[pos]-'0')),nonzero||i);
            continue;
        }
        if (prv!=i && prv1!=i){
           ans+=dp(pos+1,prv1,i,bigA||(i>(s[pos]-'0')),smallB||(i<(s1[pos]-'0')),nonzero||i);
        }
    }
    return ans;
}
void solve(int fuck){
    cin>>s>>s1;
    //cerr<<s<<" "<<s1;
    memset(cache,-1,sizeof(cache));
    personal::equal(s,s1);
    n=personal::sz(s1);
    cout<<dp(0,-1,-1,0,0,0);
}
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int tq=1;
    //cin>>tq;
    for (int i=1;i<=tq;i++){
        solve(i);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 316 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 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 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 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Correct 1 ms 332 KB Output is correct
23 Incorrect 1 ms 332 KB Output isn't correct
24 Correct 1 ms 332 KB Output is correct
25 Incorrect 1 ms 332 KB Output isn't correct
26 Incorrect 1 ms 332 KB Output isn't correct
27 Incorrect 1 ms 332 KB Output isn't correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Incorrect 1 ms 384 KB Output isn't correct
32 Correct 1 ms 332 KB Output is correct
33 Incorrect 1 ms 332 KB Output isn't correct
34 Correct 1 ms 332 KB Output is correct
35 Incorrect 1 ms 332 KB Output isn't correct
36 Incorrect 1 ms 332 KB Output isn't correct
37 Incorrect 1 ms 332 KB Output isn't correct
38 Incorrect 1 ms 332 KB Output isn't correct
39 Incorrect 1 ms 332 KB Output isn't correct
40 Correct 1 ms 332 KB Output is correct
41 Incorrect 1 ms 332 KB Output isn't correct
42 Correct 1 ms 312 KB Output is correct
43 Incorrect 1 ms 332 KB Output isn't correct
44 Incorrect 1 ms 332 KB Output isn't correct
45 Incorrect 1 ms 332 KB Output isn't correct