QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#599501 | #5482. Birthday Gift | andahe | AC ✓ | 236ms | 4128kb | C++17 | 1.9kb | 2024-09-29 05:52:46 | 2024-09-29 05:52:47 |
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 < 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 53ms
memory: 4096kb
input:
12345 200
output:
323756255
result:
ok single line: '323756255'
Test #2:
score: 0
Accepted
time: 26ms
memory: 4068kb
input:
100 87
output:
896364174
result:
ok single line: '896364174'
Test #3:
score: 0
Accepted
time: 22ms
memory: 3808kb
input:
100 35
output:
785970618
result:
ok single line: '785970618'
Test #4:
score: 0
Accepted
time: 48ms
memory: 3912kb
input:
5000 5
output:
176058968
result:
ok single line: '176058968'
Test #5:
score: 0
Accepted
time: 73ms
memory: 4128kb
input:
888888 88
output:
906317283
result:
ok single line: '906317283'
Test #6:
score: 0
Accepted
time: 94ms
memory: 3820kb
input:
9999999 99
output:
133442170
result:
ok single line: '133442170'
Test #7:
score: 0
Accepted
time: 136ms
memory: 3864kb
input:
101010101010 127
output:
893501348
result:
ok single line: '893501348'
Test #8:
score: 0
Accepted
time: 192ms
memory: 4084kb
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: 3624kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 10ms
memory: 3892kb
input:
10 10
output:
17218742
result:
ok single line: '17218742'
Test #12:
score: 0
Accepted
time: 194ms
memory: 3824kb
input:
987654321012345 188
output:
687465868
result:
ok single line: '687465868'
Test #13:
score: 0
Accepted
time: 187ms
memory: 3820kb
input:
123123123123123 123
output:
281426738
result:
ok single line: '281426738'
Test #14:
score: 0
Accepted
time: 165ms
memory: 3824kb
input:
836692041405 205
output:
878852049
result:
ok single line: '878852049'
Test #15:
score: 0
Accepted
time: 199ms
memory: 4116kb
input:
686847356299056 65
output:
734639818
result:
ok single line: '734639818'
Test #16:
score: 0
Accepted
time: 13ms
memory: 4120kb
input:
8 8
output:
159456
result:
ok single line: '159456'
Test #17:
score: 0
Accepted
time: 236ms
memory: 3824kb
input:
9000000000000000 87
output:
824013175
result:
ok single line: '824013175'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 2
output:
0
result:
ok single line: '0'