QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#780793 | #5495. 寿司晚宴 | Nigger | 100 ✓ | 117ms | 9292kb | C++14 | 2.5kb | 2024-11-25 13:16:07 | 2024-11-25 13:16:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define pb push_back
#define mp make_pair
#define READS(x); string x;cin >> x;
#define READ(x); int x;cin >> x;
#define DOUREAD(x,y); int x,y;cin >> x >> y;
#define TRIREAD(x,y,z); int x,y,z;cin >> x >> y >> z;
const int MAXN = 500;
int N,MOD;
int dp[MAXN][MAXN],F1[MAXN][MAXN],F2[MAXN][MAXN];
struct NUM{
int VAL,BIG,mask;
};
NUM A[3*MAXN];
bool cmp(NUM X,NUM Y){
return X.BIG < Y.BIG;
}
signed main(){fast
cin >> N >> MOD;
vector<int> PRIME;
PRIME.pb(2);PRIME.pb(3);
PRIME.pb(5);PRIME.pb(7);
PRIME.pb(11);PRIME.pb(13);
PRIME.pb(17);PRIME.pb(19);
for(int i = 1; i <= N-1 ; i++){
A[i].VAL = i+1;
A[i].BIG = -1;
int TEM = i+1;
int CNT = 0;
for(auto X : PRIME){
if(TEM%X == 0){
//cout << CNT << " " << i << " " << X << "div\n";
A[i].mask |= (1<<CNT);
while(TEM%X == 0) TEM /= X;
}
CNT++;
}
if(TEM != 1) A[i].BIG = TEM;
}
// for(int i = 1; i <= N-1 ; i++){
// cout << A[i].VAL << " " << A[i].BIG << "check\n";
// }
sort(A+1,A+N,cmp);
dp[0][0] = 1;
int MAXM = 255;
for(int i = 1; i <= N-1 ; i++){
if((i == 1) || (A[i].BIG != A[i-1].BIG) || (A[i].BIG == -1)){
memcpy(F1,dp,sizeof(F1));
memcpy(F2,dp,sizeof(F2));
}
for(int S1 = MAXM ; S1 >= 0 ; S1--){
for(int S2 = MAXM ; S2 >= 0 ; S2--){
if((S1&S2) == 0){
if((A[i].mask&S2) == 0) F1[S1|A[i].mask][S2] = (F1[S1|A[i].mask][S2] + F1[S1][S2])%MOD;
if((A[i].mask&S1) == 0) F2[S1][S2|A[i].mask] = (F2[S1][S2|A[i].mask] + F2[S1][S2])%MOD;
}
}
}
if((i == N-1) || (A[i].BIG != A[i+1].BIG) || (A[i].BIG == -1)){
for(int S1 = MAXM ; S1 >= 0 ; S1--){
for(int S2 = MAXM ; S2 >= 0 ; S2--){
if((S1&S2) == 0){
dp[S1][S2] = ((F1[S1][S2] + F2[S1][S2])%MOD - dp[S1][S2] + MOD)%MOD;
}
}
}
}
}
int SUM = 0;
for(int S1 = MAXM ; S1 >= 0 ; S1--){
for(int S2 = MAXM ; S2 >= 0 ; S2--){
if(((S1&S2) == 0)) SUM = (SUM + dp[S1][S2])%MOD;
}
}
cout << SUM << '\n';
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 2ms
memory: 8520kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #2:
score: 10
Accepted
time: 6ms
memory: 9028kb
input:
13 12345
output:
3438
result:
ok single line: '3438'
Test #3:
score: 10
Accepted
time: 12ms
memory: 9184kb
input:
26 1000000000
output:
447212583
result:
ok single line: '447212583'
Test #4:
score: 10
Accepted
time: 31ms
memory: 8528kb
input:
99 90000001
output:
88114119
result:
ok single line: '88114119'
Test #5:
score: 10
Accepted
time: 18ms
memory: 8716kb
input:
50 19999991
output:
16185855
result:
ok single line: '16185855'
Test #6:
score: 10
Accepted
time: 39ms
memory: 8716kb
input:
144 1000000000
output:
108118957
result:
ok single line: '108118957'
Test #7:
score: 10
Accepted
time: 60ms
memory: 9292kb
input:
197 1200007
output:
132550
result:
ok single line: '132550'
Test #8:
score: 10
Accepted
time: 75ms
memory: 8528kb
input:
289 1200007
output:
1181263
result:
ok single line: '1181263'
Test #9:
score: 10
Accepted
time: 85ms
memory: 8524kb
input:
362 99991111
output:
81393435
result:
ok single line: '81393435'
Test #10:
score: 10
Accepted
time: 117ms
memory: 8540kb
input:
499 99999999
output:
7282170
result:
ok single line: '7282170'
Extra Test:
score: 0
Extra Test Passed