QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#599499 | #5482. Birthday Gift | andahe | TL | 192ms | 4064kb | C++17 | 1.9kb | 2024-09-29 05:51:36 | 2024-09-29 05:51:36 |
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;
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: 3844kb
input:
12345 200
output:
323756255
result:
ok single line: '323756255'
Test #2:
score: 0
Accepted
time: 26ms
memory: 3872kb
input:
100 87
output:
896364174
result:
ok single line: '896364174'
Test #3:
score: 0
Accepted
time: 26ms
memory: 4032kb
input:
100 35
output:
785970618
result:
ok single line: '785970618'
Test #4:
score: 0
Accepted
time: 48ms
memory: 3764kb
input:
5000 5
output:
176058968
result:
ok single line: '176058968'
Test #5:
score: 0
Accepted
time: 73ms
memory: 3828kb
input:
888888 88
output:
906317283
result:
ok single line: '906317283'
Test #6:
score: 0
Accepted
time: 94ms
memory: 4064kb
input:
9999999 99
output:
133442170
result:
ok single line: '133442170'
Test #7:
score: 0
Accepted
time: 136ms
memory: 3772kb
input:
101010101010 127
output:
893501348
result:
ok single line: '893501348'
Test #8:
score: 0
Accepted
time: 192ms
memory: 3748kb
input:
100000000000000 224
output:
106818918
result:
ok single line: '106818918'
Test #9:
score: -100
Time Limit Exceeded
input:
1 2
output:
1