QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423117#990. Colorful ComponentsmoonstaringWA 71ms5908kbC++142.7kb2024-05-27 21:10:202024-05-27 21:10:21

Judging History

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

  • [2024-05-27 21:10:21]
  • 评测
  • 测评结果:WA
  • 用时:71ms
  • 内存:5908kb
  • [2024-05-27 21:10:20]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) (int)(a).size()
#define pb push_back
#define mk make_pair
#define fir first
#define sec second

using namespace std;
const int N = 305;
const ll M = 1e9 + 7;
int n, K;
int c[N];
ll g[N][N], dp[N][N], f[N][N], G[N];
ll ksm(ll aa, ll bb){
    if(bb < 0) return 1;
    ll as = 1;
    while(bb) {
        if(bb & 1) as = as * aa %M;
        aa = aa * aa  %M; bb >>= 1;
    }
    return as;
}
ll jx[N], ny[N];
ll C(int nn, int mm){
    if(nn < mm) return 0;
    return (jx[nn] * ny[nn - mm]%M)* ny[mm] %M;
}
int main(){

    ios :: sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >>  K;
    jx[0] = ny[0] = 1;
    L(i, 1, n){
        jx[i] = jx[i - 1] * i %M;
        ny[i] = ksm(jx[i], M - 2);
    }
    int u;
    L(i, 1 ,n) {
        cin >> u; c[u] ++; 
    }
    L(i, 1, n){
        if(c[i] == n){
            if(n <= K) return cout << ksm(n, n - 2), 0;
            else return cout << 0, 0;
        } 
    }
    g[0][0] = 1;
    L(i, 1, n){
        L(j, 1, i){
            L(k, 0, min(i - 1, K - 1)){
                if(!g[i - k - 1][j - 1]) continue;
                // if(i == j && j == 4)cerr << g[i - k - 1][j - 1] <<"!\n";
                g[i][j] += ((C(i - 1, k) * g[i - k - 1][j - 1] %M) * ksm(k + 1, k - 1) %M) * (k + 1);
                g[i][j] %= M;
            }
        }
    }
    L(i, 1 ,n) {
        g[i][1] *= ksm(i, M - 2); g[i][1] %= M;
        L(j, 1, i){
            g[i][j] *= ksm(i, j - 2);  g[i][j] %= M;
            // if(g[i][j]) cerr << i <<" " << j << " " << g[i][j] << "\n";
        }
    }
    L(i, 1, n){
        L(j, 1, i){
            if(j % 2 == 0) G[i] -= g[i][j];
            else G[i] += g[i][j];
            G[i] %= M;
        }
        // cerr << G[i] <<" ";
        if(G[i] < 0) G[i] += M;
    }
    dp[0][0] = 1;
    L(i, 1, n){
        L(j, 1, i){
            L(k, 0, i - 1){
                dp[i][j] += (C(i - 1, k) * dp[i - k - 1][j - 1]%M) * (G[k + 1] * (k + 1) %M);
                dp[i][j] %= M;
            }
        }
    }
    f[0][0] = 1;
    L(i, 1, n){
        if(c[i]){
            L(j, 1, n){
                L(k, 1, min(c[i], j)){
                    f[i][j] += (f[i - 1][j - k] * dp[c[i]][k] ) ;
                    f[i][j] %= M;
                }
            }
        }
        else {
            L(j, 1, n) f[i][j] = f[i - 1][j]; 
        }
    }
    ll ans = 0;
    L(j, 2, n){
        if(!f[n][j]) continue;
        ans += f[n][j] * ksm(n, j - 2);
        ans %= M;
    }
    cout << ans;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3704kb

input:

5 3
1
1
3
1
5

output:

125

result:

ok "125"

Test #2:

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

input:

4 2
2
1
1
1

output:

7

result:

ok "7"

Test #3:

score: 0
Accepted
time: 62ms
memory: 5908kb

input:

300 16
2
2
2
4
5
1
5
3
5
4
2
1
4
4
4
5
2
1
5
4
3
4
5
3
5
5
1
3
1
1
2
5
5
3
3
2
5
2
3
2
2
4
2
2
2
4
4
2
2
4
1
3
3
4
1
3
3
4
3
4
3
5
5
4
3
3
1
2
1
2
5
2
2
4
3
3
5
3
2
4
3
5
1
4
5
5
2
3
2
3
4
4
5
5
5
5
4
5
3
2
4
4
4
3
5
3
1
1
3
5
5
4
5
2
5
5
5
2
2
2
3
1
5
4
1
4
3
5
1
4
4
2
5
2
2
4
5
3
4
3
3
4
2
5
1
1
3...

output:

540253743

result:

ok "540253743"

Test #4:

score: 0
Accepted
time: 71ms
memory: 5756kb

input:

300 20
2
7
4
5
1
10
3
10
9
2
6
4
9
4
5
2
6
10
9
8
4
10
8
5
5
1
3
1
1
7
5
5
3
8
7
10
2
3
2
7
4
7
7
7
9
9
2
7
9
6
3
3
4
1
8
8
4
3
4
8
5
10
9
3
3
6
7
6
7
10
7
2
9
3
3
10
3
7
4
8
10
1
4
5
10
2
3
7
3
4
9
5
10
5
10
9
5
3
2
9
4
4
3
10
3
6
1
8
5
10
4
5
7
10
5
5
7
2
7
3
1
5
4
1
9
3
5
1
9
4
7
10
2
2
4
10
8
9
...

output:

616258392

result:

ok "616258392"

Test #5:

score: -100
Wrong Answer
time: 54ms
memory: 5716kb

input:

300 1
124
25
131
70
63
150
139
62
46
94
9
34
25
102
66
120
139
28
134
120
98
135
95
21
43
71
11
87
45
15
33
58
37
70
12
63
132
47
104
97
67
17
9
119
72
87
29
96
53
103
34
71
58
78
34
3
94
78
115
60
139
43
63
46
127
146
37
60
37
12
59
23
43
120
53
107
54
68
70
21
94
125
10
22
143
117
133
64
129
55
14...

output:

0

result:

wrong answer 1st words differ - expected: '450350134', found: '0'