Submission #850328

# Submission time Handle Problem Language Result Execution time Memory
850328 2023-09-16T11:19:18 Z serifefedartar Magneti (COCI21_magneti) C++17
10 / 110
151 ms 125448 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 12000;

ll expo(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
ll fact[MAXN], inv[MAXN]; 
ll dp[55][55][MAXN];

ll nCr(ll n, ll r) {
    if (r > n)
        return 0LL;
    if (r == n || r == 1 || r == 0)
        return 1LL; 
    return ((fact[n] * inv[r]) % MOD * inv[n-r]) % MOD;
}

ll dist(ll item, ll plc) {
    return nCr(item + plc - 1, item);
}

vector<ll> seq;
int main() {
    fast
    fact[0] = inv[0] = 1;
    for (ll i = 1; i < MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
        inv[i] = expo(fact[i], MOD-2); 
    }

    ll N, L;
    cin >> N >> L;

    seq = vector<ll>(N);
    for (int i = 0; i < N; i++)
        cin >> seq[i];
    sort(seq.begin(), seq.end());

    dp[0][0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int open = 0; open <= i; open++) {
            if (i != 1 && open == 0)
                continue;
            
            for (int len = 0; len < MAXN; len++) {
                dp[i][open+1][len + 1] = (dp[i][open+1][len + 1] + dp[i-1][open][len]) % MOD;
            
                if (open != 0)
                    dp[i][open][len + seq[i-1]] = (dp[i][open][len + seq[i-1]] + 2 * open * dp[i-1][open][len]) % MOD;
                
                if (open > 1)
                    dp[i][open-1][len + 2 * seq[i-1] - 1] = (dp[i][open-1][len + 2 * seq[i-1] - 1] + open * (open-1) * dp[i-1][open][len]) % MOD;
            }
        }
    }

    ll ans = 0;
    for (int d = 1; d <= L; d++) {
        ll ways = dp[N][1][d];
        ll open = L - d;
        ans = (ans + ways * dist(open, N+1)) % MOD; 
    }
    cout << ans << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:61:64: warning: iteration 11999 invokes undefined behavior [-Waggressive-loop-optimizations]
   61 |                 dp[i][open+1][len + 1] = (dp[i][open+1][len + 1] + dp[i-1][open][len]) % MOD;
      |                                           ~~~~~~~~~~~~~~~~~~~~~^
Main.cpp:60:35: note: within this loop
   60 |             for (int len = 0; len < MAXN; len++) {
      |                               ~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 151 ms 125404 KB Output is correct
2 Correct 122 ms 125448 KB Output is correct
3 Correct 8 ms 7772 KB Output is correct
4 Correct 3 ms 1884 KB Output is correct
5 Correct 24 ms 24412 KB Output is correct
6 Correct 41 ms 41380 KB Output is correct
7 Correct 114 ms 115060 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 67 ms 65576 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6804 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 7 ms 6744 KB Output is correct
4 Correct 3 ms 1884 KB Output is correct
5 Incorrect 7 ms 6636 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 47188 KB Output is correct
2 Correct 23 ms 22364 KB Output is correct
3 Correct 47 ms 47184 KB Output is correct
4 Correct 35 ms 24500 KB Output is correct
5 Incorrect 46 ms 47180 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 151 ms 125404 KB Output is correct
2 Correct 122 ms 125448 KB Output is correct
3 Correct 8 ms 7772 KB Output is correct
4 Correct 3 ms 1884 KB Output is correct
5 Correct 24 ms 24412 KB Output is correct
6 Correct 41 ms 41380 KB Output is correct
7 Correct 114 ms 115060 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 67 ms 65576 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 7 ms 6804 KB Output is correct
12 Correct 2 ms 1372 KB Output is correct
13 Correct 7 ms 6744 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Incorrect 7 ms 6636 KB Output isn't correct
16 Halted 0 ms 0 KB -