QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377612#7996. 报数 IVlingTL 10ms38880kbC++232.2kb2024-04-05 15:56:382024-04-05 15:56:39

Judging History

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

  • [2024-04-05 15:56:39]
  • 评测
  • 测评结果:TL
  • 用时:10ms
  • 内存:38880kb
  • [2024-04-05 15:56:38]
  • 提交

answer

//(ᗜ ˰ ᗜ)
// #define NDEBUG
#include <bits/stdc++.h>
using namespace std;
namespace LING
{
#ifdef ONLINE_JUDGE
#define DBG(...) ;
#define dbg(...) ;
#else
#define DBG(x) cout << "! " << #x << " = " << x << endl
#include "debug.h"
#endif
	using ll = int;
	using db = double;
#define SPO(x) fixed << setprecision(x)
#define FOR(i, l, r) for (ll i = l; i <= (r); ++i)
#define ROF(i, r, l) for (ll i = r; i >= (l); --i)
#define edl '\n'
#define fir first
#define sec second
#define str string
#define pll pair<ll, ll>
#define heap priority_queue
	// constexpr db PI = acos(-1.0);
	// constexpr db EPS = 1.0e-9;
	constexpr long long LNF = 0x3f3f3f3f3f3f3f3fLL;
	constexpr int INF = 0x3f3f3f3f;
	constexpr long long MOD = 1e9 + 7;
	constexpr ll MXN = 1e6 + 5;
	ll KSM(ll base, ll exp, ll MOD)
	{
		ll res = 1;
		base %= MOD;
		while (exp)
		{
			if (exp & 1)
				res = (res * base) % MOD;
			base = (base * base) % MOD;
			exp >>= 1;
		}
		return res;
	}
}
using namespace LING;
str n;
ll x;
ll k, m;
ll f[1005][9005];
ll l, r, p, len, a[1005];
ll cc(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
int dfs(int pos, int sum, int lim, int lead0)
{
	if (pos == 0)
	{
		for (int i = 1; i <= k - 1; i++)
		{
			sum = cc(sum);
		}
		return sum == m;
	}
	if (!lim && !lead0 && f[pos][sum] != -1)
	{
		return f[pos][sum];
	}
	int up = lim ? a[pos] : 9;
	int tmp = 0;
	for (int i = 0; i <= up; i++)
	{
		tmp += dfs(pos - 1, sum + i, lim && (i == up), lead0 && (i == 0));
		tmp %= MOD;
	}
	if (!lim && !lead0)
	{
		return f[pos][sum] = tmp;
	}
	return tmp;
}
int cal(string s)
{
	int len = 0;
	reverse(s.begin(), s.end());
	for (auto p : s)
	{
		a[++len] = p - '0';
	}
	return dfs(len, 0, 1, 1);
}
void Solve(void)
{
	for (int i = 0; i <= 1002; i++)
		for (int j = 0; j <= 9001; j++)
			f[i][j] = -1;
	cin >> n >> k >> m;
	k = min(k, 4);
	cout << cal(n) << edl;
	return;
}
int main(void)
{
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	// #ifndef ONLINE_JUDGE
	// freopen("cin.txt","r",stdin);
	// freopen("cout.txt","w",stdout);
	// #endif

	int t = 1;
	cin >> t;
	while (t--)
		Solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 38880kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 10ms
memory: 38840kb

input:

5
114 1 5
514 2 10
114514 3 7
1919810 2 13
1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79

output:

8
10
12724
504
481046284

result:

ok 5 lines

Test #3:

score: -100
Time Limit Exceeded

input:

5
3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...

output:


result: