QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#599632 | #5482. Birthday Gift | andahe | WA | 49ms | 4352kb | C++17 | 1.9kb | 2024-09-29 07:45:41 | 2024-09-29 07:45:41 |
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;
}
详细
Test #1:
score: 0
Wrong Answer
time: 49ms
memory: 4352kb
input:
12345 200
output:
0
result:
wrong answer 1st lines differ - expected: '323756255', found: '0'