Submission #330407

# Submission time Handle Problem Language Result Execution time Memory
330407 2020-11-25T06:46:47 Z 534351 Zapina (COCI20_zapina) C++17
110 / 110
82 ms 1352 KB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int INF = 1e9 + 7;
const int MAXN = 353;

int N;
int choose[MAXN][MAXN];

int add(int a, int b)
{
    a += b; if (a >= INF) a -= INF; return a;
}
int mul(int a, int b)
{
    return (ll) a * b % INF;
}
int sub(int a, int b)
{
    a -= b; if (a < 0) a += INF; return a;
}
int pwr(int a, int b)
{
    int res = 1;
    while(b > 0)
    {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }
    return res;
}
int inv(int a)
{
    return pwr(a, INF - 2);
}
int dvd(int a, int b)
{
    return mul(a, inv(b));
}

int dp[MAXN][MAXN];
int ans;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    choose[0][0] = 1;
    FOR(i, 1, N + 1)
    {
        choose[i][0] = 1;
        choose[i][i] = 1;
        FOR(j, 1, i)
        {
            choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
        }
    }
    dp[0][0] = 1;
    FOR(i, 1, N + 1)
    {
        FOR(j, 0, N + 1)
        {
            FOR(k, j, N + 1)
            {
                if (k - j == i) continue;
                dp[i][k] = add(dp[i][k], mul(dp[i - 1][j], choose[N - j][k - j]));
            }
        }
    }
    ans = sub(pwr(N, N), dp[N][N]);
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 37 ms 1144 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 9 ms 748 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 50 ms 1132 KB Output is correct
22 Correct 6 ms 748 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 12 ms 1004 KB Output is correct
25 Correct 8 ms 748 KB Output is correct
26 Correct 15 ms 876 KB Output is correct
27 Correct 70 ms 1296 KB Output is correct
28 Correct 71 ms 1260 KB Output is correct
29 Correct 71 ms 1260 KB Output is correct
30 Correct 82 ms 1260 KB Output is correct
31 Correct 72 ms 1260 KB Output is correct
32 Correct 74 ms 1260 KB Output is correct
33 Correct 74 ms 1260 KB Output is correct
34 Correct 74 ms 1280 KB Output is correct
35 Correct 74 ms 1260 KB Output is correct
36 Correct 76 ms 1352 KB Output is correct
37 Correct 76 ms 1260 KB Output is correct