QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188415 | #5482. Birthday Gift | triplem5ds# | AC ✓ | 75ms | 3852kb | C++23 | 2.7kb | 2023-09-25 20:11:25 | 2023-09-25 20:11:26 |
Judging History
answer
/// Msaa el 5ra
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for(int i = a; i < b; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll
using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;
const int N = 5e5 + 5, LG = 18, MOD = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-7;
struct Matrix {
const static int D = 90;
int a[D][D];
Matrix(int val) {
for (int i = 0; i < D; i++)
for (int j = 0; j < D; j++)
a[i][j] = val;
}
void clear() {
memset(a, 0, sizeof a);
}
void initIdentity() {
clear();
for (int i = 0; i < D; i++)
a[i][i] = 1;
}
int *operator[](int r) {
return a[r];
}
const int *operator[](int r) const {
return a[r];
}
friend Matrix operator*(const Matrix &a, const Matrix &b) {
Matrix ret(0);
for (int k = 0; k < D; k++)
for (int i = 0; i < D; i++)
if (a[i][k])
for (int j = 0; j < D; j++)
ret[i][j] = (ret[i][j] + 1ll * a[i][k] * b[k][j]) % MOD;
return ret;
}
};
Matrix raiseMatrix(Matrix trans, ll k) {
Matrix res(0);
res.initIdentity();
for (; k; k >>= 1, trans = trans * trans)
if (k & 1)
res = res * trans;
return res;
}
void doWork() {
ll a, b;
cin >> a >> b;
if (a == 1) {
cout << (b < 10) << '\n';
return;
}
if (a == 2) {
if (b < 100 && b >= 10 && (b % 10) != (b / 10)) {
cout << 1 << '\n';
} else {
cout << 0 << '\n';
}
return;
}
Matrix mat(0);
f(i, 0, 9)f(x, 0, 10)f(y, 0, 10) {
mat[i * 10 + x][((i * 10 + x) % 9) * 10 + y] += (x != y);
}
mat = raiseMatrix(mat, a - 2);
int ans = 0;
f(i, 0, 90) {
f(j, 0, 100) {
if (j % 10 == j / 10)continue;
if (j / 10 == i % 10)continue;
if ((i * 100 + j) % 225 == b) {
ans = (ans + mat[0][i]) % MOD;
}
}
}
cout << ans << '\n';
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
int t = 1;
// cin >> t;
while (t--) {
doWork();
}
}
详细
Test #1:
score: 100
Accepted
time: 15ms
memory: 3676kb
input:
12345 200
output:
323756255
result:
ok single line: '323756255'
Test #2:
score: 0
Accepted
time: 8ms
memory: 3676kb
input:
100 87
output:
896364174
result:
ok single line: '896364174'
Test #3:
score: 0
Accepted
time: 7ms
memory: 3692kb
input:
100 35
output:
785970618
result:
ok single line: '785970618'
Test #4:
score: 0
Accepted
time: 14ms
memory: 3688kb
input:
5000 5
output:
176058968
result:
ok single line: '176058968'
Test #5:
score: 0
Accepted
time: 22ms
memory: 3680kb
input:
888888 88
output:
906317283
result:
ok single line: '906317283'
Test #6:
score: 0
Accepted
time: 27ms
memory: 3692kb
input:
9999999 99
output:
133442170
result:
ok single line: '133442170'
Test #7:
score: 0
Accepted
time: 41ms
memory: 3620kb
input:
101010101010 127
output:
893501348
result:
ok single line: '893501348'
Test #8:
score: 0
Accepted
time: 59ms
memory: 3680kb
input:
100000000000000 224
output:
106818918
result:
ok single line: '106818918'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
1 2
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 3ms
memory: 3616kb
input:
10 10
output:
17218742
result:
ok single line: '17218742'
Test #12:
score: 0
Accepted
time: 59ms
memory: 3788kb
input:
987654321012345 188
output:
687465868
result:
ok single line: '687465868'
Test #13:
score: 0
Accepted
time: 56ms
memory: 3676kb
input:
123123123123123 123
output:
281426738
result:
ok single line: '281426738'
Test #14:
score: 0
Accepted
time: 49ms
memory: 3680kb
input:
836692041405 205
output:
878852049
result:
ok single line: '878852049'
Test #15:
score: 0
Accepted
time: 63ms
memory: 3620kb
input:
686847356299056 65
output:
734639818
result:
ok single line: '734639818'
Test #16:
score: 0
Accepted
time: 3ms
memory: 3696kb
input:
8 8
output:
159456
result:
ok single line: '159456'
Test #17:
score: 0
Accepted
time: 75ms
memory: 3852kb
input:
9000000000000000 87
output:
824013175
result:
ok single line: '824013175'
Test #18:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
2 2
output:
0
result:
ok single line: '0'