QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#599494#5482. Birthday GiftandaheTL 94ms4048kbC++171.9kb2024-09-29 05:49:062024-09-29 05:49:06

Judging History

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

  • [2024-09-29 05:49:06]
  • 评测
  • 测评结果:TL
  • 用时:94ms
  • 内存:4048kb
  • [2024-09-29 05:49:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod(1e9+7);
struct Matrix
{
	int n, val;
	vector<vector<ll> > a;
	Matrix(int nn, int vall)
	{
		n = nn, val = vall;
		a.resize(n, vector<ll>(n, 0));
		for(int i = 0; i < a.size(); ++i)
			for(int j = 0; j < a[i].size(); ++j)
				a[i][j] = val;
	}
	vector<ll>& operator[](int r) { return a[r]; }
	const vector<ll>& operator[](int r) const { return a[r]; }
	Matrix operator*(const Matrix &other)
	{
		Matrix ret(n, 0);
		for(int i = 0; i < n; ++i)
			for(int j = 0; j < n; ++j)
				for(int k = 0; k < n; ++k)
					ret[i][j] = (ret[i][j]+a[i][k]*other[k][j])%mod;
		return ret;
	}
	void init()
	{
		for(int i = 0; i < n; ++i) 
			a[i][i] = 1;
	}
};
Matrix Power(Matrix trans, int n)
{
	Matrix ret(90, 0);
	ret.init();
	for(; n; n >>= 1, trans = trans*trans) if(n&1)
		ret = ret*trans;
	return ret;
}
bool check(int from ,int to)
{
	if(from%10 == to%10) return 0;
	if(( (from/10)*10+to%10) % 9 == to/10) return 1;
	return 0;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("1.in","r",stdin);
	ll a, b; cin >> a >> b;
	if (a == 1) cout << (b < 10) << endl;
    if (a == 2) 
    {
        if (b < 100 && b >= 10 && (b % 10) != (b / 10)) cout << 1 << '\n';
        else cout << 0 << '\n';
    }
    Matrix mx(90, 0);
    for(int i = 0; i < 9; ++i)
    	for(int x = 0; x < 10; ++x)
    		for(int y = 0; y < 10; ++y)
                mx[i * 10 + x][((i * 10 + x) % 9) * 10 + y] += (x != y);
    mx = Power(mx, a-2);
    ll ans = 0;
    for(int i = 0; i < 90; ++i)
    	for(int j = 0; j < 100; ++j)
    	{
    		if (j % 10 == j / 10) continue;
            if (j / 10 == i % 10) continue;
            if ((i * 100 + j) % 225 == b) {
                ans = (ans + mx[0][i]) % mod;
            }
    	}
    cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 53ms
memory: 3792kb

input:

12345 200

output:

323756255

result:

ok single line: '323756255'

Test #2:

score: 0
Accepted
time: 26ms
memory: 4048kb

input:

100 87

output:

896364174

result:

ok single line: '896364174'

Test #3:

score: 0
Accepted
time: 26ms
memory: 3792kb

input:

100 35

output:

785970618

result:

ok single line: '785970618'

Test #4:

score: 0
Accepted
time: 48ms
memory: 3836kb

input:

5000 5

output:

176058968

result:

ok single line: '176058968'

Test #5:

score: 0
Accepted
time: 73ms
memory: 3792kb

input:

888888 88

output:

906317283

result:

ok single line: '906317283'

Test #6:

score: 0
Accepted
time: 94ms
memory: 3740kb

input:

9999999 99

output:

133442170

result:

ok single line: '133442170'

Test #7:

score: -100
Time Limit Exceeded

input:

101010101010 127

output:


result: