50242023-04-09 22:07:47zsomborMisztikus táblázatcpp17Accepted 100/100458ms68864 KiB
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll n, s, o, a, MOD = 1e9 + 7, ans = 1;
vector <vector <ll>> dp(2001, vector <ll>(2001, 0));
vector <vector <bool>> b(2001, vector <bool>(2001, false));

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s >> o;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        dp[i][0] = (dp[i - 1][0] * i) % MOD;
        for (int j = 1; j <= i; j++) {
            dp[i][j] = (MOD + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD;
        }
    }
    fill(b[0].begin(), b[0].end(), true);
    for (int i = 1; i <= s; i++) {
        for (int j = 0; j < o; j++) {
            cin >> a;
            b[i][a] = true;
        }
        a = 0;
        for (int j = 1; j <= n; j++) if (!b[i][j] && !b[i - 1][j]) a++;
        ans *= dp[n - o][a];
        ans %= MOD;
    }
    for (int i = 0; i < n - s; i++) {
        ans *= dp[n][n];
        ans %= MOD;
    }
    cout << ans;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted25ms65780 KiB
2Accepted24ms66104 KiB
3Accepted202ms66056 KiB
subtask25/5
4Accepted416ms66400 KiB
5Accepted439ms66736 KiB
6Accepted453ms66612 KiB
7Accepted446ms66820 KiB
subtask39/9
8Accepted28ms67028 KiB
9Accepted29ms67376 KiB
10Accepted437ms67468 KiB
11Accepted448ms67684 KiB
subtask415/15
12Accepted24ms67888 KiB
13Accepted28ms67852 KiB
14Accepted24ms67852 KiB
15Accepted28ms67980 KiB
16Accepted25ms68068 KiB
17Accepted24ms68064 KiB
18Accepted28ms68064 KiB
19Accepted25ms68160 KiB
subtask516/16
20Accepted24ms68408 KiB
21Accepted24ms68376 KiB
22Accepted446ms68356 KiB
23Accepted71ms68276 KiB
24Accepted193ms68192 KiB
subtask625/25
25Accepted27ms68160 KiB
26Accepted27ms68080 KiB
27Accepted34ms68084 KiB
28Accepted29ms68076 KiB
29Accepted27ms68076 KiB
30Accepted32ms68080 KiB
31Accepted27ms68284 KiB
32Accepted32ms68368 KiB
subtask730/30
33Accepted104ms68384 KiB
34Accepted96ms68504 KiB
35Accepted458ms68500 KiB
36Accepted75ms68588 KiB
37Accepted194ms68504 KiB
38Accepted326ms68584 KiB
39Accepted266ms68708 KiB
40Accepted87ms68716 KiB
41Accepted231ms68724 KiB
42Accepted344ms68864 KiB