Submission #44950

# Submission time Handle Problem Language Result Execution time Memory
44950 2018-04-09T20:27:15 Z SpaimaCarpatilor Asceticism (JOI18_asceticism) C++17
100 / 100
16 ms 1436 KB
#include<bits/stdc++.h>

using namespace std;

int N, K, dp[3009][3009], v0[3009], ways[3009];
const int mod = 1e9 + 7;

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int power (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int fac[200009], inv[200009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=0; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}

int coef[109][109];
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &K), K --, Prec (N + 1);


/*for (int i=1; i<=N; i++)
    coef[i][i] = 1;

for (int i=1; i<=N; i++)
    for (int j=1; j<i; j++)
        for (int k=1; k<=N; k++)
            coef[i][k] = subtract (coef[i][k], mul (coef[j][k], comb (i, j)));

for (int i=N; i>=1; i--)
    for (int j=i + 1; j<=N; j++)
        for (int k=1; k<=N; k++)
            coef[i][k] = subtract (coef[i][k], mul (coef[j][k], comb (j, i)));

for (int i=1; i<=N; i++, printf ("\n"))
    for (int j=1; j<=N; j++)
        if (coef[i][j] >= mod - 100000) printf ("%3d ", coef[i][j] - mod);
        else printf ("%3d ", coef[i][j]);
printf ("\n");
return 0;*/

dp[0][0] = 1;
/*for (int i=0; i<N; i++)
    for (int j=0; j<=N; j++)
        for (int k=1; j + k<=N; k++)
            adto (dp[i + 1][j + k], mul (dp[i][j], inv[k]));
for (int i=0; i<=N; i++)
    v0[i] = mul (fac[N], dp[N - i][N]);
that would be K! * stirling
*/
/*for (int i=1; i<=N; i++)
{
    ways[i] = power (i, N);
    for (int j=1; j<i; j++)
        ways[i] = subtract (ways[i], mul (ways[j], comb (i, j)));
}
for (int i=0; i<=N; i++)
    v0[i] = ways[N - i];*/
/*for (int K2=0; K2<=N; K2++)
    for (int j=1; j<=N-K2; j++)
    {
        int curr = mul (power (j, N), comb (N - K2, j));
        if (j % 2 == (N - K2) % 2) adto (v0[K2], curr);
        else v0[K2] = subtract (v0[K2], curr);
    }
for (int i=1; i<=N; i++)
    printf ("%d ", v0[i]);
printf ("\n");
int ans = 0;
for (int K2=K; K2<=N; K2++)
{
    int curr = mul (v0[K2], comb (K2, K));
    if (K2 % 2 == K % 2) adto (ans, curr);
    else ans = subtract (ans, curr);
}*/
int ans = 0;
for (int j=1; j + K<=N; j++)
{
    int curr = mul (power (j, N), comb (N + 1, j + K + 1));
    if (j % 2 == (N - K) % 2) adto (ans, curr);
    else ans = subtract (ans, curr);
}
printf ("%d\n", ans);
return 0;
}

Compilation message

asceticism.cpp: In function 'int main()':
asceticism.cpp:35:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf ("%d %d", &N, &K), K --, Prec (N + 1);
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 2 ms 760 KB Output is correct
26 Correct 2 ms 760 KB Output is correct
27 Correct 2 ms 760 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 2 ms 760 KB Output is correct
30 Correct 2 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 2 ms 760 KB Output is correct
26 Correct 2 ms 760 KB Output is correct
27 Correct 2 ms 760 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 2 ms 760 KB Output is correct
30 Correct 2 ms 760 KB Output is correct
31 Correct 16 ms 1404 KB Output is correct
32 Correct 16 ms 1404 KB Output is correct
33 Correct 16 ms 1408 KB Output is correct
34 Correct 14 ms 1412 KB Output is correct
35 Correct 6 ms 1416 KB Output is correct
36 Correct 5 ms 1420 KB Output is correct
37 Correct 4 ms 1420 KB Output is correct
38 Correct 3 ms 1420 KB Output is correct
39 Correct 8 ms 1420 KB Output is correct
40 Correct 12 ms 1436 KB Output is correct