QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#599633 | #5482. Birthday Gift | andahe | AC ✓ | 237ms | 4124kb | C++17 | 1.9kb | 2024-09-29 07:45:54 | 2024-09-29 07:45:55 |
Judging History
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, ll 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; return 0;}
if (a == 2)
{
if (b < 100 && b >= 10 && (b % 10) != (b / 10)) cout << 1 << '\n';
else cout << 0 << '\n';
return 0;
}
Matrix mx(90, 0);
for(int i = 0; i < 90; ++i)
for(int j = 0; j < 90; ++j)
mx[i][j] += check(i, j);
mx = Power(mx, a-3);
Matrix f(90, 0);
for(int i = 1; i <= 9; ++i) f[0][(i%9)*10+i] = 1;
f = f*mx;
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/10) * 100 + j) % 225 == b) {
ans = (ans + f[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: 4048kb
input:
12345 200
output:
323756255
result:
ok single line: '323756255'
Test #2:
score: 0
Accepted
time: 28ms
memory: 3828kb
input:
100 87
output:
896364174
result:
ok single line: '896364174'
Test #3:
score: 0
Accepted
time: 28ms
memory: 3828kb
input:
100 35
output:
785970618
result:
ok single line: '785970618'
Test #4:
score: 0
Accepted
time: 50ms
memory: 3840kb
input:
5000 5
output:
176058968
result:
ok single line: '176058968'
Test #5:
score: 0
Accepted
time: 71ms
memory: 4048kb
input:
888888 88
output:
906317283
result:
ok single line: '906317283'
Test #6:
score: 0
Accepted
time: 93ms
memory: 4124kb
input:
9999999 99
output:
133442170
result:
ok single line: '133442170'
Test #7:
score: 0
Accepted
time: 145ms
memory: 3820kb
input:
101010101010 127
output:
893501348
result:
ok single line: '893501348'
Test #8:
score: 0
Accepted
time: 193ms
memory: 4112kb
input:
100000000000000 224
output:
106818918
result:
ok single line: '106818918'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
1 2
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 28ms
memory: 3808kb
input:
10 10
output:
17218742
result:
ok single line: '17218742'
Test #12:
score: 0
Accepted
time: 189ms
memory: 3820kb
input:
987654321012345 188
output:
687465868
result:
ok single line: '687465868'
Test #13:
score: 0
Accepted
time: 185ms
memory: 3832kb
input:
123123123123123 123
output:
281426738
result:
ok single line: '281426738'
Test #14:
score: 0
Accepted
time: 163ms
memory: 4120kb
input:
836692041405 205
output:
878852049
result:
ok single line: '878852049'
Test #15:
score: 0
Accepted
time: 197ms
memory: 4112kb
input:
686847356299056 65
output:
734639818
result:
ok single line: '734639818'
Test #16:
score: 0
Accepted
time: 16ms
memory: 3852kb
input:
8 8
output:
159456
result:
ok single line: '159456'
Test #17:
score: 0
Accepted
time: 237ms
memory: 3812kb
input:
9000000000000000 87
output:
824013175
result:
ok single line: '824013175'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 2
output:
0
result:
ok single line: '0'