QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#308231#5495. 寿司晚宴james1BadCreeper100 ✓42ms4460kbC++141.6kb2024-01-19 19:25:102024-01-19 19:25:11

Judging History

你现在查看的是最新测评结果

  • [2024-01-19 19:25:11]
  • 评测
  • 测评结果:100
  • 用时:42ms
  • 内存:4460kb
  • [2024-01-19 19:25:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int prime[] = {2, 3, 5, 7, 11, 13, 17, 19};

int n, P; 
int f[256][256], g1[256][256], g2[256][256]; // g1 表示 1 取 big,g2 表示 2 取 big

struct Number {
    int val, S, big; 
    void init(void) {
        int tmp = val; big = -1; 
        for (int i = 0; i < 8; ++i) if (tmp % prime[i] == 0) {
            S |= 1 << i; 
            while (tmp % prime[i] == 0) tmp /= prime[i];
        }
        if (tmp > 1) big = tmp; 
    }
    bool operator< (const Number &a) const { return big < a.big; }
} a[505];

int main(void) {
    ios::sync_with_stdio(0); 
    cin >> n >> P; 
    for (int i = 1; i < n; ++i) a[i].val = i + 1, a[i].init();
    sort(a + 1, a + n); 
    for (int i = f[0][0] = 1; i < n; ++i) {
        if (i == 1 || a[i].big == -1 || a[i].big != a[i - 1].big)
            memcpy(g1, f, sizeof g1), 
            memcpy(g2, f, sizeof g2);
        for (int j = 255; j >= 0; --j) for (int k = 255; k >= 0; --k) 
            if ((j & k) == 0) {
                if ((a[i].S & k) == 0) g1[j | a[i].S][k] = (g1[j | a[i].S][k] + g1[j][k]) % P; 
                if ((a[i].S & j) == 0) g2[j][k | a[i].S] = (g2[j][k | a[i].S] + g2[j][k]) % P; 
            }
        if (i == n - 1 || a[i].big == -1 || a[i].big != a[i + 1].big) {
            for (int j = 0; j < 256; ++j) for (int k = 0; k < 256; ++k)
                if ((j & k) == 0) f[j][k] = (0ll + g1[j][k] + g2[j][k] - f[j][k]) % P; 
        }
    }
    int ans = 0; 
    for (int i = 0; i < 256; ++i) for (int j = 0; j < 256; ++j)
        if ((i & j) == 0) ans = (ans + f[i][j]) % P;
    cout << (ans + P) % P;  
    return 0; 
}

詳細信息

Test #1:

score: 10
Accepted
time: 1ms
memory: 4312kb

input:

2 1

output:

0

result:

ok single line: '0'

Test #2:

score: 10
Accepted
time: 2ms
memory: 4404kb

input:

13 12345

output:

3438

result:

ok single line: '3438'

Test #3:

score: 10
Accepted
time: 4ms
memory: 4404kb

input:

26 1000000000

output:

447212583

result:

ok single line: '447212583'

Test #4:

score: 10
Accepted
time: 10ms
memory: 4460kb

input:

99 90000001

output:

88114119

result:

ok single line: '88114119'

Test #5:

score: 10
Accepted
time: 3ms
memory: 4452kb

input:

50 19999991

output:

16185855

result:

ok single line: '16185855'

Test #6:

score: 10
Accepted
time: 15ms
memory: 4376kb

input:

144 1000000000

output:

108118957

result:

ok single line: '108118957'

Test #7:

score: 10
Accepted
time: 15ms
memory: 4444kb

input:

197 1200007

output:

132550

result:

ok single line: '132550'

Test #8:

score: 10
Accepted
time: 27ms
memory: 4308kb

input:

289 1200007

output:

1181263

result:

ok single line: '1181263'

Test #9:

score: 10
Accepted
time: 32ms
memory: 4416kb

input:

362 99991111

output:

81393435

result:

ok single line: '81393435'

Test #10:

score: 10
Accepted
time: 42ms
memory: 4392kb

input:

499 99999999

output:

7282170

result:

ok single line: '7282170'

Extra Test:

score: 0
Extra Test Passed