Submission #514513

# Submission time Handle Problem Language Result Execution time Memory
514513 2022-01-18T08:33:25 Z Killer2501 Zapina (COCI20_zapina) C++14
110 / 110
384 ms 452 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 4e2+5;
const int M = 26;
const ll inf = 1e15;
const ll mod = 1e9+7;
const ld ex = 1e-9;
int n, t, k, m, d[N], lab[N];
ll ans, tong, a[N], b[N], c[N], dp[2][N][2], cnt;
string s;
struct node
{
    int x, y, val;
    int vx, vy;
    node(){}
    node(int _x, int _vx, int _y, int _vy)
    {
        x = _x;
        vx = _vx;
        y = _y;
        vy = _vy;
    }
};
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n&1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
ll C(ll u, ll v)
{
    if(u > v)return 0;
    return a[v] * b[u] % mod * b[v-u] % mod;
}
void add(ll& x, ll y)
{
    x += y;
    if(x >= mod)x -= mod;
}
void sol()
{
    cin >> n;
    a[0] = b[0] = 1;
    for(int i = 1; i <= n; i ++)
    {
        a[i] = a[i-1] * i % mod;
        b[i] = b[i-1] * pw(i, mod-2) % mod;
    }
    dp[0][0][0] = 1;
    for(int i = 0; i < n; i ++)
    {
        int nxt = (i&1)^1;
        memset(dp[nxt], 0, sizeof(dp[nxt]));
        for(int j = 0; j <= n; j ++)
        {
            for(int p = 0; p <= n-j; p ++)
            {
                if(p != i+1)
                {
                    add(dp[nxt][p+j][0], dp[i&1][j][0] * C(p, n-j) % mod);
                    add(dp[nxt][p+j][1], dp[i&1][j][1] * C(p, n-j) % mod);
                }
                else
                {
                    add(dp[nxt][p+j][1], dp[i&1][j][1] * C(p, n-j) % mod);
                    add(dp[nxt][p+j][1], dp[i&1][j][0] * C(p, n-j) % mod);
                }
            }
        }
    }
    cout << dp[n&1][n][1];
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
	{
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}

Compilation message

zapina.cpp: In function 'int main()':
zapina.cpp:93:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zapina.cpp:94:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 176 ms 320 KB Output is correct
18 Correct 2 ms 300 KB Output is correct
19 Correct 38 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 242 ms 332 KB Output is correct
22 Correct 27 ms 324 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 51 ms 332 KB Output is correct
25 Correct 35 ms 204 KB Output is correct
26 Correct 68 ms 316 KB Output is correct
27 Correct 347 ms 332 KB Output is correct
28 Correct 342 ms 332 KB Output is correct
29 Correct 341 ms 324 KB Output is correct
30 Correct 343 ms 332 KB Output is correct
31 Correct 347 ms 328 KB Output is correct
32 Correct 359 ms 332 KB Output is correct
33 Correct 354 ms 332 KB Output is correct
34 Correct 361 ms 452 KB Output is correct
35 Correct 364 ms 440 KB Output is correct
36 Correct 363 ms 332 KB Output is correct
37 Correct 384 ms 332 KB Output is correct