QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129147 | #5031. 核 | pandapythoner# | 10 | 6ms | 3820kb | C++20 | 2.7kb | 2023-07-21 23:54:10 | 2024-07-04 00:52:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rnd(234);
const ll inf = 1e18;
;
ll bin_pow(ll x, ll n, ll m) {
if (n == 0) {
return 1;
}
ll a = bin_pow(x, n / 2, m);
a = (a * a) % m;
if (n & 1) {
a = (a * x) % m;
}
return a;
}
ll rev(ll x, ll m) {
return bin_pow(x, m - 2, m);
}
ll n, q, mod;
ll biba(ll r) {
ll a = (bin_pow(q, r + 1, mod) - 1) * rev(q - 1, mod) % mod;
a = bin_pow(a, n - r, mod);
ll b = bin_pow(q, r * (r - 1) / 2, mod);
ll c = 1;
for (ll i = 0; i < r; i += 1) {
c = (c * (bin_pow(q, n - i, mod) - 1)) % mod;
}
return a * b % mod * c % mod;
}
ll get_rank(vector<vector<ll>> a, ll n, ll m) {
int j = 0;
for (int i = 0; i < n; i += 1) {
int t = -1;
for (int k = j; k < n; k += 1) {
if (a[k][i] != 0) {
t = k;
break;
}
}
if (t == -1) {
continue;
}
swap(a[t], a[j]);
ll f = rev(a[j][i], m);
for (int k = 0; k < n; k += 1) {
a[j][k] = (a[j][k] * f) % m;
}
for (int k = j + 1; k < n; k += 1) {
if (a[k][i] != 0) {
ll g = a[k][i];
for (int q = 0; q < n; q += 1) {
a[k][q] = (a[k][q] + m - a[j][q] * g % m) % m;
}
}
}
j += 1;
}
return j;
}
ll solve_slow(vector<vector<ll>> &b, int i) {
if (i == n * n) {
if (get_rank(b, n, q) != n) {
return 0;
}
auto bi = b;
for (int i = 0; i < n; i += 1) {
bi[i][i] = (bi[i][i] + q - 1) % q;
}
ll rnk = get_rank(bi, n, q);
ll pw = bin_pow(q, n * (n - rnk), mod - 1);
ll rs = bin_pow(3, pw, mod);
return rs;
}
ll rs = 0;
for (int f = 0; f < q; f += 1) {
b[i / n][i % n] = f;
rs = (rs + solve_slow(b, i + 1)) % mod;
}
return rs;
}
ll solve_slow() {
vector<vector<ll>> b(n, vector<ll>(n));
ll rs = solve_slow(b, 0);
return rs;
}
ll solve() {
ll sm = 0;
for (ll r = 0; r <= n; r += 1) {
ll b = biba(r);
sm = (sm + b) % mod;
}
cout << sm << " " << bin_pow(q, n * n, mod) << "\n";
return sm;
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n >> q >> mod;
ll rs = solve_slow();
cout << rs << "\n";
return 0;
}
/*
3 2 1000000007
1 1 1000000007
*/
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 3820kb
input:
1 2 540053233
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
2 2 156542707
output:
43046970
result:
ok 1 number(s): "43046970"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
1 2 186225229
output:
9
result:
ok 1 number(s): "9"
Test #4:
score: 0
Accepted
time: 6ms
memory: 3604kb
input:
3 3 109884329
output:
100602209
result:
ok 1 number(s): "100602209"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 2 144802297
output:
9
result:
ok 1 number(s): "9"
Subtask #2:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #6:
score: 0
Time Limit Exceeded
input:
20 21992843 328859143
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Memory Limit Exceeded
Test #26:
score: 0
Memory Limit Exceeded
input:
998818 198334853 998244353
output:
result:
Subtask #5:
score: 0
Memory Limit Exceeded
Test #36:
score: 0
Memory Limit Exceeded
input:
9909956 720431399 720431401
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%