QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694555#6522. Digit ModeShuishui#WA 1ms3716kbC++143.6kb2024-10-31 18:11:102024-10-31 18:11:10

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 18:11:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3716kb
  • [2024-10-31 18:11:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define Sz(x) (int)(x).size()
#define bit(x) (1ll << (x))
using ll = long long;
using db = double;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vd = vector<db>;
mt19937 mrand(time(0));

const int mod = 1e9 + 7, CN = 1002;
int inv[CN + 8], fac[CN + 8], ifac[CN + 8];

int C(int a, int b) {
    if (b > a || b < 0) return 0;
    return 1LL * fac[a] * ifac[b] % mod * ifac[a - b] % mod; 
}

void init() {
    inv[1] = fac[0] = ifac[0] = 1;
    for (int i = 2; i <= CN; i++) 
        inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
    for (int i = 1; i <= CN; i++)
        fac[i] = 1LL * fac[i - 1] * i % mod, ifac[i] = 1LL * ifac[i - 1] * inv[i] % mod;    
}

struct Mint;
Mint operator+(Mint, Mint);
 
struct Mint {
    constexpr Mint(long long val = 0) : val((val % mod + mod) % mod) {
    }
    unsigned& operator*() {
        return val;
    }
    const unsigned& operator*() const {
        return val;
    }
    Mint& operator+=(Mint r) {
        return *this = *this + r;
    }
    unsigned val;
};
 
Mint operator+(Mint l, Mint r) {
    return *l + *r < mod ? *l + *r : *l + *r - mod;
}
 
Mint operator-(Mint l, Mint r) {
    return *l < *r ? *l - *r + mod : *l - *r;
}
 
Mint operator*(Mint l, Mint r) {
    return 1ull * *l * *r % mod;
}
 
Mint power(Mint l, unsigned long long r) {
    Mint x = 1;
    for (; r; r >>= 1, l = l * l)
        if (r & 1)
            x = x * l;
    return x;
}

Mint operator/(Mint l, Mint r) {
    return l * power(r, mod - 2);
}


Mint fnum[2][52][52], fval[2][52][52];


void solve(void)
{
	string s;
	cin >> s;
	vi dig;
	int n = Sz(s);
	// cerr << n << "\n";
	for (int i = 0; i < n; i++)
		dig.pb(s[i] - '0');

	Mint ans = 0;
	vi ad(10);


	auto calc = [&](int num)
	{
		int onum = num;
		num = n;
		for (int t = 0; t <= 1; t++)
			for (int a = 0; a <= num; a++)
				for (int b = 0; b <= num; b++)
					fnum[t][a][b] = fval[t][a][b] = 0;
		fnum[1][0][0] = 1;
		for (int i = 9; i >= 0; i--)
		{
			int u = i & 1, v = i & 1 ^ 1;

			for (int a = 0; a <= num; a++)
				for (int b = 0; b <= num; b++)
					fnum[v][a][b] = fval[v][a][b] = 0;

			for (int a = 0; a <= num; a++)
				for (int c = 0; c + a + ad[i] <= num && c + a <= onum; c++)
					for (int b = 0; b <= num; b++)
					{
						Mint pnum = fnum[u][a][b], pval = fval[u][a][b];
						if (c + ad[i] > b)
						{
							fnum[v][a + c][c + ad[i]] += pnum * C(onum - a, c);
							fval[v][a + c][c + ad[i]] += pnum * C(onum - a, c) * i;
						}
						else
						{
							fnum[v][a + c][b], pnum * C(onum - a, c);
							fval[v][a + c][b], pval * C(onum - a, c);
						}
					}
		}
		
		for (int i = 0; i <= num; i++)
			ans += fval[1][onum][i];
		
	};

	for (int i = 1; i < n; i++)
		for (int j = 1; j < 10; j++)
		{
			ad[j]++;
			calc(n - i - 1);
			ad[j]--;
		}

	for (int i = 0; i < n; i++)
	{
		for (int j = (i) ? 0 : 1; j < dig[i]; j++)
		{
			ad[j]++;
			calc(n - i - 1);
			ad[j]--;
		}
		ad[dig[i]]++;
	}

	int mx = 0;
	for (int i = 1; i <= 9; i++)
		if (ad[i] >= ad[mx])
			mx = i;
	ans += mx;
	cout << *ans << "\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// cout << fixed << setprecision(10);
	init();
	int T = 1;
	cin >> T;
	for (int i = 1; i <= T; i++)
	solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3716kb

input:

5
9
99
999
99999
999999

output:

9
9
9
9
9

result:

wrong answer 1st numbers differ - expected: '45', found: '9'