QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#110578#2573. Two PermutationsyllcmAC ✓90ms14120kbC++171.5kb2023-06-02 21:35:202023-06-02 21:35:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-02 21:35:21]
  • 评测
  • 测评结果:AC
  • 用时:90ms
  • 内存:14120kb
  • [2023-06-02 21:35:20]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
    int x = 0; bool op = 0;
    char c = getchar();
    while(!isdigit(c))op |= (c == '-'), c = getchar();
    while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return op ? -x : x;
}
const int N = 110;
const int P = 1e9 + 7;
void add(int &a, int b) {a += b; a >= P ? a -= P : 0;}
void sub(int &a, int b) {a -= b; a < 0 ? a += P : 0;}
int n, k;
int f[2][N][N * N];
int main() { 
    n = read(); k = read();
    f[1][0][0] = 1;
    for(int i = 1; i <= n; i++) {
        swap(f[0], f[1]);
        for(int x = 0; x <= i; x++)for(int z = 0; z <= i * i; z++)f[1][x][z] = 0;
        for(int x = 0; x <= i; x++) {
            for(int z = 0; z <= i * i; z++) {
                int y = i - 1 - x;
                if(f[0][x][z] == 0)continue;
                // cout << i << ' ' << x << ' ' << y << ' ' << z << ' ' << f[0][x][z] << endl;
                add(f[1][x + 1][z + i], 1ll * (n - x - 2 * y) * f[0][x][z] % P);
                add(f[1][x][z], 1ll * (n - x - 2 * y) * (n - x - 2 * y - 1) % P * f[0][x][z] % P);
                add(f[1][x + 2][z + 2 * i], 1ll * y * y % P * f[0][x][z] % P);
                add(f[1][x + 1][z + i], 2ll * (n - x - 2 * y) * y % P * f[0][x][z] % P);
            }
        }
    }
    printf("%d\n", f[1][n][k]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 14120kb

input:

2 4

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 11ms
memory: 13856kb

input:

3 7

output:

12

result:

ok 1 number(s): "12"

Test #3:

score: 0
Accepted
time: 3ms
memory: 13948kb

input:

4 10

output:

24

result:

ok 1 number(s): "24"

Test #4:

score: 0
Accepted
time: 1ms
memory: 13888kb

input:

4 14

output:

96

result:

ok 1 number(s): "96"

Test #5:

score: 0
Accepted
time: 10ms
memory: 14000kb

input:

5 10

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 8ms
memory: 14056kb

input:

5 15

output:

120

result:

ok 1 number(s): "120"

Test #7:

score: 0
Accepted
time: 8ms
memory: 13948kb

input:

5 21

output:

2400

result:

ok 1 number(s): "2400"

Test #8:

score: 0
Accepted
time: 8ms
memory: 13896kb

input:

6 21

output:

720

result:

ok 1 number(s): "720"

Test #9:

score: 0
Accepted
time: 3ms
memory: 13872kb

input:

6 30

output:

25920

result:

ok 1 number(s): "25920"

Test #10:

score: 0
Accepted
time: 8ms
memory: 14052kb

input:

6 27

output:

106560

result:

ok 1 number(s): "106560"

Test #11:

score: 0
Accepted
time: 8ms
memory: 13940kb

input:

20 300

output:

644873710

result:

ok 1 number(s): "644873710"

Test #12:

score: 0
Accepted
time: 8ms
memory: 14000kb

input:

20 139

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 18ms
memory: 14008kb

input:

30 470

output:

491424690

result:

ok 1 number(s): "491424690"

Test #14:

score: 0
Accepted
time: 25ms
memory: 13892kb

input:

30 500

output:

8436035

result:

ok 1 number(s): "8436035"

Test #15:

score: 0
Accepted
time: 22ms
memory: 13880kb

input:

40 1000

output:

617159088

result:

ok 1 number(s): "617159088"

Test #16:

score: 0
Accepted
time: 27ms
memory: 13892kb

input:

40 900

output:

729805907

result:

ok 1 number(s): "729805907"

Test #17:

score: 0
Accepted
time: 34ms
memory: 14052kb

input:

60 1830

output:

16340084

result:

ok 1 number(s): "16340084"

Test #18:

score: 0
Accepted
time: 31ms
memory: 13996kb

input:

60 2000

output:

832198921

result:

ok 1 number(s): "832198921"

Test #19:

score: 0
Accepted
time: 78ms
memory: 14000kb

input:

100 5050

output:

437918130

result:

ok 1 number(s): "437918130"

Test #20:

score: 0
Accepted
time: 83ms
memory: 14052kb

input:

100 700

output:

0

result:

ok 1 number(s): "0"

Test #21:

score: 0
Accepted
time: 90ms
memory: 14120kb

input:

100 10000

output:

0

result:

ok 1 number(s): "0"