90 pts 求调,WA on #4
查看原帖
90 pts 求调,WA on #4
634960
ICE_Dice1024楼主2023/8/13 12:19

Wrong answer on #4,翻帖无果。

#include <algorithm>
#include <cstring>
#include <cstdio>
#define FOR(i,a,b) for (int i = (a); (i) < (b); (i) ++)
#define ROF(i,a,b) for (int i = (a); (i) >= (b); (i) --)

typedef long long LL;

constexpr int stat[] = {0, 0, 0, 0, 1, 0, 0, 0, 2, 0};

LL f[11][10][3][3][3];
int a[11];

LL solve(LL num)
{
    memset(f, 0, sizeof(f));

    ROF (i, 10, 0) a[i] = num % 10, num /= 10;

    FOR (i, 0, a[0]) f[0][i][0][0][stat[i]] = 1;

    int s[3] = {0, 0, stat[a[0]]};
    bool fl = true;
    FOR (i, 0, 10)
    {
        // do not reach the upper bound
        FOR (j, 0, 10) FOR (k, 0, 3) FOR (l, 0, 3) FOR (m, 0, 3) FOR (n, 0, 10)
        {
            if (m && stat[n] && (m ^ stat[n])) continue;
            int st = j == n ? std::min(k + 1, 2) : 0;
            f[i + 1][n][st][std::max(st, l)][std::max(m, stat[n])] += f[i][j][k][l][m];
        }

        // reach the upper bound
        if (!fl) continue;

        FOR (n, 0, a[i + 1])
        {
            if (s[2] && stat[n] && (s[2] ^ stat[n])) continue;
            int st = a[i] == n ? std::min(s[0] + 1, 2) : 0;
            f[i + 1][n][st][std::max(st, s[1])][std::max(s[2], stat[n])] ++;
        }

        if (s[2] && stat[a[i + 1]] && (s[2] ^ stat[a[i + 1]]))
        { fl = false; continue; }

        s[0] = a[i] == a[i + 1] ? std::min(s[0] + 1, 2) : 0;
        s[1] = std::max(s[0], s[1]), s[2] = std::max(s[2], stat[a[i + 1]]);
    }

    LL ret = fl;
    FOR (i, 0, 10) FOR (j, 0, 3) FOR (k, 0, 3)
        ret += f[10][i][j][2][k];
    return ret;
}

int main()
{
    LL L, R;
    scanf("%lld%lld", &L, &R);
    printf("%lld\n", solve(R) - solve(L - 1));

    return 0;
}

2023/8/13 12:19
加载中...