QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#403238#8047. DFS Order 4XZC0920AC ✓798ms8860kbC++141.5kb2024-05-01 22:33:112024-05-01 22:33:13

Judging History

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

  • [2024-05-01 22:33:13]
  • 评测
  • 测评结果:AC
  • 用时:798ms
  • 内存:8860kb
  • [2024-05-01 22:33:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef uint64_t u64;
typedef __uint128_t u128;
const int N = 805;
int n, mod, f[N][N][2], inv[N], ans;
struct fastmod 
{
    int m; 
    u64 b;
    fastmod() {}
    fastmod(int m): m(m), b(((u128)1 << 64) / m) {}
    int reduce(u64 a) 
    {
        int r = a - ((u128)a * b >> 64) * m;
        return r < m ? r: r - m;
    }
}z;
int main()
{
    scanf("%d%d", &n, &mod); z = mod; inv[1] = 1; f[1][0][0] = 1;
    for(int i = 2; i <= n; i++) inv[i] = z.reduce((u64)(mod - mod / i) * inv[mod % i]);
    for(int i = 2; i <= n; i++) 
    {
        f[i][i - 1][0] = inv[i];
        for(int j = i - 1; j >= 1; j--) 
        {
            if(!(f[i][j][0] + f[i][j][1])) continue;
            for(int k = 1; k <= j; k++) 
            {
                if(k == j) f[i][0][0] = z.reduce(f[i][0][0] + (u64)(f[i][j][0] + f[i][j][1]) * f[j][0][0]);
                else if(k >= 2) 
                {
                    f[i][j - k][0] = z.reduce(f[i][j - k][0] + (u64)(f[i][j][0] + f[i][j][1]) * z.reduce((u64)f[k][0][0] * z.reduce((u64)inv[j] * k)));
                    f[i][j - k][1] = z.reduce(f[i][j - k][1] + (u64)(f[i][j][0] + f[i][j][1]) * (mod - f[j][j - k][0] + z.reduce((u64)(f[j][j - k + 1][0] + f[j][j - k + 1][1]) * (mod - inv[j - k + 1]))));
                }
            }
        }
    }
    ans = f[n][0][0];
    for(int i = 1; i <= n; i++) ans = z.reduce((u64)ans * i);
    printf("%d\n", ans);
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3792kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 2ms
memory: 4216kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 665ms
memory: 8244kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 776ms
memory: 8860kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 681ms
memory: 8240kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 720ms
memory: 8580kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 659ms
memory: 8184kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 735ms
memory: 8400kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 791ms
memory: 8500kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 775ms
memory: 8852kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 720ms
memory: 8584kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 798ms
memory: 8512kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

score: 0
Accepted
time: 0ms
memory: 4116kb

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed