# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
741986 | 2023-05-15T09:43:11 Z | irmuun | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 10 ms | 212 KB |
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define ff first #define ss second #define all(s) s.begin(),s.end() ll cnt[20],c8[20]; ll check(ll n){ string s=to_string(n); for(ll i=1;i<s.size();i++){ if(s[i]==s[i-1]){ return 0; } } for(ll i=2;i<s.size();i++){ if(s[i]==s[i-2]){ return 0; } } return 1; } ll pal(ll n){ if(n==0){ return 0; } string s=to_string(n); ll sz=s.size(); ll res=0; for(ll i=1;i<sz;i++){ res+=cnt[i]*9; } //cout<<res<<"\n"; for(ll i=0;i<sz;i++){ for(ll j=(i==0?1:0);j<s[i]-48;j++){ //cout<<"str "<<s.substr(0,i)<<char(j+48)<<"\n"; if((i>0&&char(j+48)==s[i-1])||(i>1&&char(j+48)==s[i-2])){ continue; } if(i==0){ //cout<<cnt[sz-i]<<' '; res+=cnt[sz-i]; } else{ //cout<<c8[sz-i-1]<<' '; res+=c8[sz-i-1]; } //cout<<"\n"; } if((i>0&&s[i]==s[i-1])||(i>1&&s[i]==s[i-2])){ break; } } //cout<<check(n); //cout<<"\n"; return res+check(n); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cnt[0]=1; cnt[1]=1; cnt[2]=9; c8[0]=1; c8[1]=8; c8[2]=64; for(ll i=3;i<=18;i++){ cnt[i]=cnt[i-1]*8; c8[i]=c8[i-1]*8; } ll a,b; cin>>a>>b; if(b-a<=100000){ ll ans=0; for(ll i=a;i<=b;i++){ ans+=check(i); } cout<<ans; return 0; } cout<<pal(b)-pal(a-1); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 10 ms | 212 KB | Output is correct |
4 | Correct | 3 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 3 ms | 212 KB | Output is correct |
15 | Correct | 4 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 7 ms | 212 KB | Output is correct |
20 | Correct | 3 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 0 ms | 212 KB | Output is correct |
27 | Correct | 0 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 0 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 0 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 1 ms | 212 KB | Output is correct |
41 | Correct | 1 ms | 212 KB | Output is correct |
42 | Correct | 0 ms | 212 KB | Output is correct |
43 | Correct | 0 ms | 212 KB | Output is correct |
44 | Correct | 0 ms | 212 KB | Output is correct |
45 | Correct | 0 ms | 212 KB | Output is correct |