Submission #217949

# Submission time Handle Problem Language Result Execution time Memory
217949 2020-03-31T09:52:31 Z Vimmer Zapina (COCI20_zapina) C++14
110 / 110
180 ms 3244 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 dp[351][351][2], binnom[351][351];


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

    int n;

    cin >> n;

    binnom[0][0] = 1;

    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= i; j++)
        {
            if (j == 0) binnom[i][j] = 1;
              else if (j == i) binnom[i][j] = 1;
                else binnom[i][j] = fx(binnom[i - 1][j - 1], binnom[i - 1][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 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 432 KB Output is correct
6 Correct 4 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 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 432 KB Output is correct
6 Correct 4 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 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 88 ms 2552 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 24 ms 1664 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 115 ms 2808 KB Output is correct
22 Correct 18 ms 1536 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 28 ms 1792 KB Output is correct
25 Correct 21 ms 1664 KB Output is correct
26 Correct 37 ms 1920 KB Output is correct
27 Correct 160 ms 3108 KB Output is correct
28 Correct 163 ms 3192 KB Output is correct
29 Correct 161 ms 3192 KB Output is correct
30 Correct 162 ms 3192 KB Output is correct
31 Correct 168 ms 3192 KB Output is correct
32 Correct 165 ms 3196 KB Output is correct
33 Correct 175 ms 3192 KB Output is correct
34 Correct 177 ms 3192 KB Output is correct
35 Correct 180 ms 3132 KB Output is correct
36 Correct 176 ms 3192 KB Output is correct
37 Correct 178 ms 3244 KB Output is correct