Submission #217944

# Submission time Handle Problem Language Result Execution time Memory
217944 2020-03-31T09:39:57 Z Vimmer Zapina (COCI20_zapina) C++14
110 / 110
212 ms 3228 KB
#include <bits/stdc++.h>

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100005
#define M ll(1e9 + 7)

using namespace std;

typedef long double ld;
typedef long long ll;
typedef short int si;

ll fx(ll a, ll b) {return (a + b) % M;}

ll mx(ll a, ll b) {return (a * b) % M;}

ll binpow(ll a, ll b)
{
    if (b == 0) return 1ll;

    ll s = binpow(a, b / 2);

    if (b % 2) return mx(mx(s, s), a);

    return mx(s, s);
}

ll dp[351][351][2];

ll fact[351], binnom[351][351];

ll calc(ll n, ll k)
{
    if (k == 0) return 1;

    return mx(fact[n], binpow(mx(fact[n - k], fact[k]), M - 2));
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;

    cin >> n;

    fact[0] = 1;

    fact[1] = 1;

    for (ll i = 2; i <= n; i++) fact[i] = mx(fact[i - 1], i);

    for (ll i = 0; i <= n; i++)
      for (ll j = 0; j <= i; j++) binnom[i][j] = calc(i, j);

    dp[0][n][0] = 1;

    for (ll i = 2; i <= n; i++) dp[0][n - i][0] = binnom[n][i];

    dp[0][n - 1][1] = binnom[n][1];

    for (int i = 0; i < n - 1; i++)
      for (int j = 0; j <= n; j++)
        for (int f = 0; f <= 1; f++)
          {
              for (int u = 0; u <= j; u++)
              {
                if (u == i + 2) dp[i + 1][j - u][1] = fx(dp[i + 1][j - u][1], mx(binnom[j][u], dp[i][j][f]));
                     else  dp[i + 1][j - u][f] = fx(dp[i + 1][j - u][f], mx(binnom[j][u], dp[i][j][f]));
              }
        }

    cout << dp[n - 1][0][1] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 100 ms 2680 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 27 ms 1664 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 133 ms 2808 KB Output is correct
22 Correct 22 ms 1536 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 34 ms 1788 KB Output is correct
25 Correct 35 ms 1660 KB Output is correct
26 Correct 47 ms 2040 KB Output is correct
27 Correct 184 ms 3192 KB Output is correct
28 Correct 192 ms 3192 KB Output is correct
29 Correct 189 ms 3192 KB Output is correct
30 Correct 176 ms 3192 KB Output is correct
31 Correct 181 ms 3192 KB Output is correct
32 Correct 201 ms 3192 KB Output is correct
33 Correct 192 ms 3192 KB Output is correct
34 Correct 191 ms 3192 KB Output is correct
35 Correct 212 ms 3192 KB Output is correct
36 Correct 194 ms 3228 KB Output is correct
37 Correct 192 ms 3192 KB Output is correct