QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377583#7996. 报数 IVlingTL 31ms74308kbC++172.1kb2024-04-05 15:35:492024-04-05 15:35:49

Judging History

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

  • [2024-04-05 15:35:49]
  • 评测
  • 测评结果:TL
  • 用时:31ms
  • 内存:74308kb
  • [2024-04-05 15:35:49]
  • 提交

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 = long long;
	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];
int l, r, p, len, a[1005];
ll get(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
int dfs(int pos, int sum, int limit, int lead)
{
	if (!pos)
	{
		FOR(i, 1, k - 1)
		sum = get(sum);
		return sum == m;
	}
	if (!limit && f[pos][sum] != -1 && !lead)
		return f[pos][sum];
	int res = 0, up = limit ? a[pos] : 9;
	for (int i = 0; i <= up; i++)
	{
		res += dfs(pos - 1, sum + i, limit && i == up, lead && !i);
		res %= MOD;
	}
	return limit ? res : (lead ? res : f[pos][sum] = res);
}
int cal(str n)
{
	memset(f, -1, sizeof f);
	len = 0;
	ROF(i, n.size() - 1, 0)
	a[++len] = n[i] - '0';
	return dfs(len, 0, 1, 1);
}
void Solve(void)
{
	cin >> n >> k >> m;
	k = min(k, 4LL);
	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: 7ms
memory: 74308kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 31ms
memory: 74256kb

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: