Submission #562442

#TimeUsernameProblemLanguageResultExecution timeMemory
562442KenjikrabPalindrome-Free Numbers (BOI13_numbers)C++14
15 / 100
1 ms300 KiB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int cal1(int x)
{
    if(x==1)return 9;
    if(x==2)return 81;
    return 81*pow(8,x-2);
}
int cal2(string s)
{
    int ret=0;
    int l=s.length();
    bool chk=true;
    if(l==1)
    {
        return '9'-s[0]+1;
    }
    for(int i=0;i<l;i++)
    {
        if(s[i]!='9') chk=false;
    }
    if(chk)return 0;
    int temp=pow(8,l-2);
    ret+=9*temp*('9'-s[0]);
    ret+=temp*('9'-s[1]-((s[1]+1<=s[0])? 1:0));
    //cout<<ret<<" ";
    for(int i=2;i<l;i++)
    {
        temp/=8;
        int cnt=0;
        for(int j=s[i]+1;j<='9';j++)
        {
            if(j!=s[i-1] && j!=s[i-2])cnt++;
        }
        ret+=temp*cnt;
        //cout<<ret<<" ";
    }
    return ret;
}
signed main()//99999999999
{
    int ans=0;
    string s1,s2;
    cin>>s1>>s2;
    for(int i=s1.length()+1;i<=s2.length();i++)
    {
        ans+=cal1(i);
    }
    ans+=cal2(s1);
    ans-=cal2(s2);
    bool chk=s2[0]!=s2[1];
    for(int i=2;chk&&i<s2.length();i++)
    {
        if(s2[i]==s2[i-1]||s2[i]==s2[i-2]) chk=false;
    }
    if(chk) ans++;
    cout<<ans;
    return 0;
}

Compilation message (stderr)

numbers.cpp: In function 'int main()':
numbers.cpp:46:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=s1.length()+1;i<=s2.length();i++)
      |                             ~^~~~~~~~~~~~~
numbers.cpp:53:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i=2;chk&&i<s2.length();i++)
      |                      ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...