QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188381 | #5482. Birthday Gift | IsaacMoris# | AC ✓ | 250ms | 4044kb | C++14 | 2.6kb | 2023-09-25 19:45:06 | 2023-09-25 19:45:06 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 100 + 5, mod = 1e9 + 7;
struct Matrix {
int n;
int val;
vector<vector<int> > a;
Matrix(int _n, int _val) {
n = _n, val = _val;
a.resize(n, vector<int>(n, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
a[i][j] = (i == j ? val : 0);
}
Matrix operator*(const Matrix &other) {
Matrix res(n, 0);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++)
res.a[i][j] = (1LL * res.a[i][j] + 1LL * a[i][k] * other.a[k][j]) % mod;
return res;
}
};
Matrix power(Matrix a, ll p) {
Matrix res(a.n, 1), temp = a;
while (p) {
if (p & 1)
res = res * temp;
temp = temp * temp;
p >>= 1;
}
return res;
}
void doWork() {
ll a, b;
cin >> a >> b;
if (a <= 3) {
int ans = 0;
for (int i = 1; i < 1000; i++) {
int len = 0, temp = i, last = -1;
while (temp) {
len++;
if (temp % 10 == last) {
len = 1e5;
break;
}
last = temp % 10;
temp /= 10;
}
if (len == a && i % 225 == b) {
ans++;
}
}
cout << ans;
return;
}
Matrix mat(90, 0);
for (int rem = 0; rem < 9; rem++) {
for (int last = 0; last < 10; last++) {
int from = rem * 10 + last;
for (int cur = 0; cur < 10; cur++) {
if (cur == last)continue;
int to = ((rem * 10 + cur) % 9) * 10 + cur;
// cout << from << " " << to << "\n";
mat.a[from][to]++;
}
}
}
// return;
mat = power(mat, a - 2);
int ans = 0;
for (int to = 0; to < 90; to++) {
int rem = to / 10;
int last = to % 10;
for (int cur = 0; cur < 100; cur++) {
if (cur % 10 == (cur / 10) % 10 || (cur / 10) % 10 == last)continue;
if ((rem * 100 + cur) % 225 == b) {
ans = (ans + mat.a[0][to]) % mod;
}
}
}
cout << ans;
}
int main() {
IO
int t = 1;
//cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
doWork();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 57ms
memory: 3740kb
input:
12345 200
output:
323756255
result:
ok single line: '323756255'
Test #2:
score: 0
Accepted
time: 28ms
memory: 4032kb
input:
100 87
output:
896364174
result:
ok single line: '896364174'
Test #3:
score: 0
Accepted
time: 28ms
memory: 4036kb
input:
100 35
output:
785970618
result:
ok single line: '785970618'
Test #4:
score: 0
Accepted
time: 52ms
memory: 3808kb
input:
5000 5
output:
176058968
result:
ok single line: '176058968'
Test #5:
score: 0
Accepted
time: 78ms
memory: 3636kb
input:
888888 88
output:
906317283
result:
ok single line: '906317283'
Test #6:
score: 0
Accepted
time: 100ms
memory: 3812kb
input:
9999999 99
output:
133442170
result:
ok single line: '133442170'
Test #7:
score: 0
Accepted
time: 146ms
memory: 3836kb
input:
101010101010 127
output:
893501348
result:
ok single line: '893501348'
Test #8:
score: 0
Accepted
time: 205ms
memory: 3788kb
input:
100000000000000 224
output:
106818918
result:
ok single line: '106818918'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
1 2
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 14ms
memory: 3836kb
input:
10 10
output:
17218742
result:
ok single line: '17218742'
Test #12:
score: 0
Accepted
time: 207ms
memory: 3796kb
input:
987654321012345 188
output:
687465868
result:
ok single line: '687465868'
Test #13:
score: 0
Accepted
time: 199ms
memory: 3780kb
input:
123123123123123 123
output:
281426738
result:
ok single line: '281426738'
Test #14:
score: 0
Accepted
time: 175ms
memory: 3808kb
input:
836692041405 205
output:
878852049
result:
ok single line: '878852049'
Test #15:
score: 0
Accepted
time: 209ms
memory: 3740kb
input:
686847356299056 65
output:
734639818
result:
ok single line: '734639818'
Test #16:
score: 0
Accepted
time: 10ms
memory: 4044kb
input:
8 8
output:
159456
result:
ok single line: '159456'
Test #17:
score: 0
Accepted
time: 250ms
memory: 4044kb
input:
9000000000000000 87
output:
824013175
result:
ok single line: '824013175'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
2 2
output:
0
result:
ok single line: '0'