Submission #574732

# Submission time Handle Problem Language Result Execution time Memory
574732 2022-06-09T11:14:01 Z MohammadAghil Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
1 ms 348 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 = 18, 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;}

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;
     rep(i,0,sz(dig)){
          rep(k,0,dig[i]){
               if((i && k == dig[i-1]) || (i > 1 && k == dig[i-2])) 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;
}

int main(){
     cin.tie(0) -> sync_with_stdio(0); 
     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) dp[l][i][j] += dp[l-1][j][k];
               }
          }
     }
     ll a, b; cin >> b >> a;
     cout << f(a+1) - f(b) << '\n';
     return 0; 
}

Compilation message

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