답안 #217943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217943 2020-03-31T09:39:15 Z Vimmer Zapina (COCI20_zapina) C++14
110 / 110
193 ms 3360 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 (int i = 0; i < n; 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 + 1) 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][0][1] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 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 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 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 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 103 ms 2648 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 26 ms 1664 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 126 ms 2812 KB Output is correct
22 Correct 20 ms 1536 KB Output is correct
23 Correct 6 ms 896 KB Output is correct
24 Correct 35 ms 1784 KB Output is correct
25 Correct 25 ms 1664 KB Output is correct
26 Correct 44 ms 1912 KB Output is correct
27 Correct 176 ms 3176 KB Output is correct
28 Correct 178 ms 3192 KB Output is correct
29 Correct 192 ms 3172 KB Output is correct
30 Correct 185 ms 3192 KB Output is correct
31 Correct 192 ms 3336 KB Output is correct
32 Correct 180 ms 3192 KB Output is correct
33 Correct 186 ms 3192 KB Output is correct
34 Correct 191 ms 3360 KB Output is correct
35 Correct 193 ms 3192 KB Output is correct
36 Correct 186 ms 3192 KB Output is correct
37 Correct 187 ms 3192 KB Output is correct