Submission #1090276

# Submission time Handle Problem Language Result Execution time Memory
1090276 2024-09-18T06:37:53 Z Gourougourou Conspiracy (POI11_kon) C++17
90 / 100
3000 ms 103464 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5001;
const int MOD = 1e4+7;
int deg[MAXN], cnt[MAXN], fact[MAXN];

int fastPow(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return (a * fastPow(a, b-1)) % MOD;
    return fastPow((a*a)%MOD, b/2);
}
int rev(int a) {
    return fastPow(a, MOD-2);
}
int choose(int a, int b) {
    return (((fact[a]*rev(fact[a-b])) % MOD) * rev(fact[b])) % MOD;
}
int main()
{
    fact[0] = 1;
    for (int i = 1; i<MAXN; ++i) fact[i] = (i*fact[i-1]) % MOD;
    int n, m = 0; cin >> n;
    for (int i = 0; i<n; ++i) {
        int sz,a; cin >> sz;
        deg[i] = sz; ++cnt[sz];
        m += sz;
        while (sz--) {
            cin >> a;
        }
    }
    m /= 2;
    sort(deg,deg+n);
    int same = 1, degSum = 0, x = 1, ans = 0;
    for (int i = n-1; i; --i, ++x) {
        if (i != n-1) {
            if (deg[i] == deg[i+1]) ++same;
            else same = 1;
        }
        degSum += deg[i];
        if (degSum - (x*(x-1))/2 == m) {
            ans += choose(cnt[deg[i]], same);
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 4 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 732 KB Output is correct
2 Correct 90 ms 2856 KB Output is correct
3 Correct 1153 ms 13608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 860 KB Output is correct
2 Correct 116 ms 4176 KB Output is correct
3 Correct 541 ms 18084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 3104 KB Output is correct
2 Correct 263 ms 9044 KB Output is correct
3 Correct 884 ms 29484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 4948 KB Output is correct
2 Correct 632 ms 20564 KB Output is correct
3 Correct 2061 ms 69168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1391 ms 47784 KB Output is correct
2 Correct 904 ms 31272 KB Output is correct
3 Execution timed out 3049 ms 103464 KB Time limit exceeded
4 Halted 0 ms 0 KB -