Submission #574742

# Submission time Handle Problem Language Result Execution time Memory
574742 2022-06-09T11:33:28 Z MohammadAghil Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
1 ms 340 KB
      #include <bits/stdc++.h>
  #pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) x.begin(), x.end()
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e5+5, d = 11, lg = 19, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

bool chk(ll a){
     vector<int> d;
     while(a) d.pb(a%10), a /= 10;
     rep(i,1,sz(d)) if(d[i-1] == d[i] || (i>1 && d[i-2] == d[i])) return false;
     return true;
}

ll dp[lg][d][d];

ll f(ll a){
     vector<int> dig;
     while(a) dig.pb(a%10), a /= 10; reverse(all(dig));
     ll res = 0;
     if(sz(dig)) res = dp[sz(dig)-1][10][10]; 
     rep(i,0,sz(dig)){
          rep(k,0,dig[i]){
               if((i && k == dig[i-1]) || (i > 1 && k == dig[i-2]) || (!k && !i)) continue;
               res += dp[sz(dig)-i-1][(i?dig[i-1]:10)][k]; 
          }
          if((i && dig[i] == dig[i-1]) || (i > 1 && dig[i] == dig[i-2])) break;
     }
     return res;
}

void init(){
     rep(i,0,d) rep(j,0,d) dp[0][i][j] = 1;
     rep(l,1,lg){
          rep(i,0,d){
               rep(j,0,d){
                    rep(k,0,d-1) if(k - i && k - j) {
                         if(i == 10 && j == 10 && k == 0) dp[l][i][j] += dp[l-1][i][i];
                         else dp[l][i][j] += dp[l-1][j][k];
                    }
               }
          }
     }
}

ll slv1(ll l, ll r){
     return f(r+1) - f(l);
}

ll slv2(ll l, ll r){
     ll res = 0;
     rep(i,l,r+1) res += chk(i);
     return res;
}

int main(){
     cin.tie(0) -> sync_with_stdio(0); init();
     ll l, r; cin >> l >> r;
     cout << slv1(l, r) << '\n';
     return 0; 
}

Compilation message

numbers.cpp: In function 'll f(ll)':
numbers.cpp:31:6: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   31 |      while(a) dig.pb(a%10), a /= 10; reverse(all(dig));
      |      ^~~~~
numbers.cpp:31:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   31 |      while(a) dig.pb(a%10), a /= 10; reverse(all(dig));
      |                                      ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 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 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 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 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct