Submission #1121058

# Submission time Handle Problem Language Result Execution time Memory
1121058 2024-11-28T11:08:35 Z nasir_bashirov Palindrome-Free Numbers (BOI13_numbers) C++11
100 / 100
2 ms 508 KB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define db long double
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define int long long

int dp[20][11][11][2], a, b;

int solve(string &s, int pos, int d1, int d2, int f){
    // cout << pos << " " << d1 << " " << d2 << " " << f << endl;
    if(pos == s.size()) return 1;
    if(dp[pos][d1][d2][f] != -1)    return dp[pos][d1][d2][f];
    int res = 0;
    if(d2 == 10)    res += solve(s, pos + 1, d1, d2, 0);
    for(int i = (d2 == 10 ? 1 : 0); i <= (f ? s[pos] - '0' : 9); i++){
        if(i == d1 or i == d2)  continue;
        res += solve(s, pos + 1, d2, i, (f & ((s[pos] - '0') == i)));
    }
    return dp[pos][d1][d2][f] = res;
}

void fmain(){
    cin >> a >> b;
    a--;
    string sa = to_string(a), sb = to_string(b);
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 11; j++){
            for(int z = 0; z < 11; z++){
                dp[i][j][z][0] = dp[i][j][z][1] = -1;
            }
        }
    }
    int resa = (a == -1 ? 0 : solve(sa, 0, 10, 10, 1));
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 11; j++){
            for(int z = 0; z < 11; z++){
                dp[i][j][z][0] = dp[i][j][z][1] = -1;
            }
        }
    }
    int resb = solve(sb, 0, 10, 10, 1);
    cout << resb - resa;
}
 
signed main(){
    fastio;
    int tmr = 1;
    // cin >> tmr;
    while(tmr--){
        fmain();
    }
    
}

Compilation message

numbers.cpp: In function 'long long int solve(std::string&, long long int, long long int, long long int, long long int)':
numbers.cpp:25:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     if(pos == s.size()) return 1;
      |        ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 508 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct