QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#468592 | #5495. 寿司晚宴 | little_sun | 100 ✓ | 107ms | 6080kb | C++14 | 1.9kb | 2024-07-08 21:45:17 | 2024-07-08 21:45:17 |
Judging History
answer
#include <bits/stdc++.h>
#define R register
#define ll long long
#define sum(a, b, mod) (((a) + (b)) % mod)
#define Add(a, b, mod) ((a) = sum(a, b, mod))
#define meow(cat...) fprintf(stderr, cat)
const ll MaxN = 3e2 + 10;
const ll pr[] = {2, 3, 5, 7, 11, 13, 17, 19};
struct node
{
ll val, big, msk;
void calc()
{
ll tmp = val; big = -1;
for (ll i = 0; i < 8; i++)
if (tmp % pr[i] == 0)
{
msk |= (1 << i);
while (tmp % pr[i] == 0)
tmp /= pr[i];
}
if (tmp > 1) big = tmp;
}
} a[MaxN << 1];
ll n, p, f[MaxN][MaxN];
ll f1[MaxN][MaxN], f2[MaxN][MaxN];
ll cmp(node a, node b) { return a.big < b.big; }
signed main()
{
scanf("%lld%lld", &n, &p);
for (ll i = 1; i <= n - 1; i++)
a[i].val = i + 1, a[i].calc();
std::sort(a + 1, a + n, cmp), f[0][0] = 1;
for (ll i = 1; i < n; i++)
{
if (i == 1 || a[i].big != a[i - 1].big || a[i].big == -1)
{
memcpy(f1, f, sizeof(f));
memcpy(f2, f, sizeof(f));
}
for (ll j = 255; ~j; j--)
for (ll k = 255; ~k; k--)
{
if (j & k) continue;
if ((a[i].msk & k) == 0)
Add(f1[j | a[i].msk][k], f1[j][k], p);
if ((a[i].msk & j) == 0)
Add(f2[j][k | a[i].msk], f2[j][k], p);
}
if (i == n - 1 || a[i].big != a[i + 1].big || a[i].big == -1)
{
for (ll j = 0; j < (1 << 8); j++)
for (ll k = 0; k < (1 << 8); k++)
f[j][k] = sum(f1[j][k] + f2[j][k], p - f[j][k], p);
}
}
ll ans = 0;
for (ll j = 0; j <= 255; j++)
for (ll k = 0; k <= 255; k++)
if ((j & k) == 0) Add(ans, f[j][k], p);
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 0ms
memory: 5948kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #2:
score: 10
Accepted
time: 5ms
memory: 6036kb
input:
13 12345
output:
3438
result:
ok single line: '3438'
Test #3:
score: 10
Accepted
time: 6ms
memory: 5888kb
input:
26 1000000000
output:
447212583
result:
ok single line: '447212583'
Test #4:
score: 10
Accepted
time: 30ms
memory: 5940kb
input:
99 90000001
output:
88114119
result:
ok single line: '88114119'
Test #5:
score: 10
Accepted
time: 16ms
memory: 6024kb
input:
50 19999991
output:
16185855
result:
ok single line: '16185855'
Test #6:
score: 10
Accepted
time: 41ms
memory: 5976kb
input:
144 1000000000
output:
108118957
result:
ok single line: '108118957'
Test #7:
score: 10
Accepted
time: 54ms
memory: 5900kb
input:
197 1200007
output:
132550
result:
ok single line: '132550'
Test #8:
score: 10
Accepted
time: 73ms
memory: 6080kb
input:
289 1200007
output:
1181263
result:
ok single line: '1181263'
Test #9:
score: 10
Accepted
time: 82ms
memory: 6080kb
input:
362 99991111
output:
81393435
result:
ok single line: '81393435'
Test #10:
score: 10
Accepted
time: 107ms
memory: 6036kb
input:
499 99999999
output:
7282170
result:
ok single line: '7282170'
Extra Test:
score: 0
Extra Test Passed