# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
230433 | 2020-05-10T06:49:28 Z | mehrdad_sohrabi | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 5 ms | 512 KB |
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define pb push_back #define pii pair < ll , ll > #define F first #define S second #define endl '\n' #define int long long #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #define kill(x) return cout<<x<<'\n', 0; using namespace std; const int N=20,M=10; bool check(vector <int> a){ for (int i=1;i<a.size();i++){ if (a[i]==a[i-1]) return 0; } for (int i=2;i<a.size();i++){ if (a[i]==a[i-2]) return 0; } return 1; } ll dp[N]; ll p[N]; ll solve(ll x){ if (x<10) return x+1; vector <int> a; ll k=x; while(k){ a.pb(k%10); k/=10; } ll ans=0; ll z=a.size(); reverse(a.begin(),a.end()); vector <int> b; for (int i=0;i<a.size();i++){ z--; for (int j=0;j<a[i];j++){ if (i==0 && j==0) continue; b.pb(j); if (check(b)){ if (i==0){ ans+=p[z]/8*9; // cout << p[z]/8*9 << endl;; b.pop_back(); continue; } ans+=p[z]; // cout << p[z] << endl; } b.pop_back(); } b.pb(a[i]); } if (check(b)) ans++; ans+=dp[(ll)a.size()-1]; return ans; } int32_t main(){ p[0]=1; for (int i=1;i<N;i++){ p[i]=p[i-1]*8; } dp[0]=1; dp[1]=10; for (int i=2;i<N;i++){ dp[i]=dp[i-1]+9*9*p[i-2]; } ll l,r; cin >> l >> r; ll ans=solve(r); // cout << ans << endl; if (l!=0) ans-=solve(l-1); cout << ans << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 512 KB | Output is correct |
4 | Correct | 4 ms | 256 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 4 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 256 KB | Output is correct |
9 | Correct | 4 ms | 256 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 4 ms | 384 KB | Output is correct |
18 | Correct | 4 ms | 384 KB | Output is correct |
19 | Correct | 4 ms | 256 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 256 KB | Output is correct |
7 | Correct | 4 ms | 256 KB | Output is correct |
8 | Correct | 4 ms | 256 KB | Output is correct |
9 | Correct | 4 ms | 256 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 256 KB | Output is correct |
15 | Correct | 4 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 256 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
19 | Correct | 4 ms | 256 KB | Output is correct |
20 | Correct | 5 ms | 256 KB | Output is correct |
21 | Correct | 5 ms | 308 KB | Output is correct |
22 | Correct | 4 ms | 256 KB | Output is correct |
23 | Correct | 4 ms | 256 KB | Output is correct |
24 | Correct | 5 ms | 384 KB | Output is correct |
25 | Correct | 4 ms | 256 KB | Output is correct |
26 | Correct | 5 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 256 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 4 ms | 256 KB | Output is correct |
30 | Correct | 4 ms | 256 KB | Output is correct |
31 | Correct | 4 ms | 256 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 256 KB | Output is correct |
35 | Correct | 5 ms | 256 KB | Output is correct |
36 | Correct | 4 ms | 256 KB | Output is correct |
37 | Correct | 4 ms | 256 KB | Output is correct |
38 | Correct | 5 ms | 384 KB | Output is correct |
39 | Correct | 4 ms | 256 KB | Output is correct |
40 | Correct | 4 ms | 256 KB | Output is correct |
41 | Correct | 4 ms | 256 KB | Output is correct |
42 | Correct | 4 ms | 256 KB | Output is correct |
43 | Correct | 5 ms | 384 KB | Output is correct |
44 | Correct | 5 ms | 256 KB | Output is correct |
45 | Correct | 5 ms | 256 KB | Output is correct |