# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
562442 | Kenjikrab | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 1 ms | 300 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |