답안 #499584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499584 2021-12-28T21:29:58 Z Dan4Life Palindrome-Free Numbers (BOI13_numbers) C++17
23.3333 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll // delete if causing problems
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define mod(a) (a+MOD)%MOD
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

const int maxn = 3e5+10; // change when needed!
const int MOD = 1e9+7; // same!
const int INF = 2e9;
const ll LINF = 4e18;
int n, m, x, y, l, r, k, q, t;
map<int, int> M, N;
string a, b,s;
int dp[20][12][12][2][2];

bool chk(string a){
    int n = (int)a.size();
    for(int i = 0; i < n-1; i++){
        if(i<n-2 and a[i]==a[i+2]) return false;
        if(a[i]==a[i+1]) return false;
    }
    return true;
}

int recur(int pos=0, int last=10, int last2=11, bool sm=0, bool le=1)
{
    int n = (int)s.size();
    if(pos==n) return dp[pos][last][last2][sm][le]=1;
    if(dp[pos][last][last2][sm][le]!=-1) return dp[pos][last][last2][sm][le];
    int limit = 9, ans = 0;
    if(!sm) limit = s[pos]-'0';
    for(int d = 0; d <= limit; d++)
    {
        if(d==last or d==last2) continue;
        bool SM = sm, LE = le;
        if(!SM and d<limit) SM=true;
        if(LE and d) LE=false;
        ans+=recur(pos+1, LE?10:d, LE?10:last, SM);
    }
    return dp[pos][last][last2][sm][le]=ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> a >> b; memset(dp, -1, sizeof(dp)); s = b;
    int ans = recur(); memset(dp, -1, sizeof(dp)); s = a;
    cout << ans-recur()+chk(a);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Incorrect 0 ms 332 KB Output isn't correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Incorrect 0 ms 332 KB Output isn't correct
12 Incorrect 0 ms 332 KB Output isn't correct
13 Incorrect 0 ms 332 KB Output isn't correct
14 Incorrect 0 ms 332 KB Output isn't correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Incorrect 0 ms 332 KB Output isn't correct
17 Incorrect 0 ms 332 KB Output isn't correct
18 Correct 0 ms 332 KB Output is correct
19 Incorrect 1 ms 332 KB Output isn't correct
20 Incorrect 1 ms 332 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Incorrect 0 ms 332 KB Output isn't correct
8 Incorrect 0 ms 332 KB Output isn't correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Incorrect 0 ms 332 KB Output isn't correct
11 Incorrect 0 ms 332 KB Output isn't correct
12 Incorrect 0 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Incorrect 0 ms 332 KB Output isn't correct
15 Incorrect 0 ms 332 KB Output isn't correct
16 Incorrect 0 ms 332 KB Output isn't correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Incorrect 1 ms 332 KB Output isn't correct
23 Incorrect 0 ms 332 KB Output isn't correct
24 Correct 1 ms 332 KB Output is correct
25 Incorrect 1 ms 332 KB Output isn't correct
26 Incorrect 0 ms 332 KB Output isn't correct
27 Incorrect 1 ms 332 KB Output isn't correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Correct 1 ms 332 KB Output is correct
33 Incorrect 1 ms 332 KB Output isn't correct
34 Correct 1 ms 332 KB Output is correct
35 Incorrect 1 ms 332 KB Output isn't correct
36 Incorrect 0 ms 332 KB Output isn't correct
37 Incorrect 1 ms 332 KB Output isn't correct
38 Incorrect 0 ms 332 KB Output isn't correct
39 Incorrect 1 ms 332 KB Output isn't correct
40 Correct 1 ms 332 KB Output is correct
41 Incorrect 1 ms 332 KB Output isn't correct
42 Correct 0 ms 332 KB Output is correct
43 Incorrect 0 ms 332 KB Output isn't correct
44 Incorrect 1 ms 332 KB Output isn't correct
45 Incorrect 1 ms 332 KB Output isn't correct