QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#492877 | #5495. 寿司晚宴 | Gemini7X | 100 ✓ | 49ms | 4920kb | C++14 | 1.8kb | 2024-07-26 16:42:57 | 2024-07-26 16:42:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x)
{
T sgn = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
x *= sgn;
}
int n, mod;
int qmod(int x) { return x >= mod ? x - mod : x; }
int s[505];
int prime[8] = {2, 3, 5, 7, 11, 13, 17, 19};
int f[1 << 8][1 << 8], tmp[1 << 8][1 << 8], g[1 << 8][1 << 8], h[1 << 8][1 << 8];
vector<int> vec[505];
int main()
{
read(n); read(mod);
for (int i = 2; i <= n; i++)
{
int x = i;
for (int j = 0; j < 8; j++)
{
while (x % prime[j] == 0)
{
s[i] |= 1 << j;
x /= prime[j];
}
}
vec[x].push_back(i);
}
f[0][0] = 1;
for (int i : vec[1])
{
memcpy(tmp, f, sizeof(tmp));
for (int s1 = 0; s1 < 256; s1++)
for (int s2 = 0; s2 < 256; s2++)
{
if ((s[i] & s1) == 0) f[s1][s2 | s[i]] = qmod(f[s1][s2 | s[i]] + tmp[s1][s2]);
if ((s[i] & s2) == 0) f[s1 | s[i]][s2] = qmod(f[s1 | s[i]][s2] + tmp[s1][s2]);
}
}
for (int i = 2; i <= 500; i++) if (vec[i].size())
{
memcpy(g, f, sizeof(g)); memcpy(h, f, sizeof(h));
for (int j : vec[i])
{
for (int s2 = 0; s2 < 256; s2++) if ((s2 & s[j]) == 0)
for (int s1 = 255; ~s1; s1--)
g[s1 | s[j]][s2] = qmod(g[s1 | s[j]][s2] + g[s1][s2]);
for (int s1 = 0; s1 < 256; s1++) if ((s1 & s[j]) == 0)
for (int s2 = 255; ~s2; s2--)
h[s1][s2 | s[j]] = qmod(h[s1][s2 | s[j]] + h[s1][s2]);
}
for (int s1 = 0; s1 < 256; s1++)
for (int s2 = 0; s2 < 256; s2++)
f[s1][s2] = qmod(qmod(g[s1][s2] + h[s1][s2]) - f[s1][s2] + mod);
}
int ans = 0;
for (int s1 = 0; s1 < 256; s1++)
for (int s2 = 0; s2 < 256; s2++)
ans = qmod(ans + f[s1][s2]);
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 4340kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #2:
score: 10
Accepted
time: 2ms
memory: 4472kb
input:
13 12345
output:
3438
result:
ok single line: '3438'
Test #3:
score: 10
Accepted
time: 3ms
memory: 4832kb
input:
26 1000000000
output:
447212583
result:
ok single line: '447212583'
Test #4:
score: 10
Accepted
time: 11ms
memory: 4768kb
input:
99 90000001
output:
88114119
result:
ok single line: '88114119'
Test #5:
score: 10
Accepted
time: 6ms
memory: 4768kb
input:
50 19999991
output:
16185855
result:
ok single line: '16185855'
Test #6:
score: 10
Accepted
time: 15ms
memory: 4920kb
input:
144 1000000000
output:
108118957
result:
ok single line: '108118957'
Test #7:
score: 10
Accepted
time: 21ms
memory: 4836kb
input:
197 1200007
output:
132550
result:
ok single line: '132550'
Test #8:
score: 10
Accepted
time: 26ms
memory: 4764kb
input:
289 1200007
output:
1181263
result:
ok single line: '1181263'
Test #9:
score: 10
Accepted
time: 36ms
memory: 4784kb
input:
362 99991111
output:
81393435
result:
ok single line: '81393435'
Test #10:
score: 10
Accepted
time: 49ms
memory: 4836kb
input:
499 99999999
output:
7282170
result:
ok single line: '7282170'
Extra Test:
score: 0
Extra Test Passed