Submission #340088

# Submission time Handle Problem Language Result Execution time Memory
340088 2020-12-26T21:12:35 Z Hazem Zapina (COCI20_zapina) C++14
110 / 110
865 ms 2540 KB
/*
ID: tmhazem1
LANG: C++14
TASK: pprime
*/

#include <bits/stdc++.h>
using namespace std;

#define S second
#define F first
#define LL long long

const int N = 4e2 + 10;


LL LINF = 100000000000000000;
LL INF = 1000000000;
int MOD = 1e9+7;

int n;
int fac[N];
int dp[N][N][2],inverse[N];
int C1[N][N];

int mult(LL a,LL b){
    return (a*b)%MOD;
}

int fastpow(int n,int k){

    LL ret = 1;
    while(k){
        if(k&1)ret = mult(ret,n);
        k /= 2;
        n = mult(n,n);
    }
    return ret;
}

int add(LL a,LL b){
    return (a+b)%MOD;
}

int divide(LL a,LL b){
    return mult(a,fastpow(b,MOD-2));
}

int C(LL n,LL k){

    return divide(fac[n],mult(fac[k],fac[n-k]));
}

int solve(int i,int j,bool q){

    if(i==n+1)
        return j==n&&q;

    if(dp[i][j][q]!=-1)
        return dp[i][j][q];

    LL ret = 0;
    for(int k=0;k<=n-j;k++)
        ret = add(ret,mult(C1[n-j][k],solve(i+1,j+k,q|(k==i))));

    return dp[i][j][q] = ret;
}

int main()
{
    //freopen("out.txt","w",stdout);
    scanf("%d",&n);
    memset(dp,-1,sizeof(dp));

    fac[0] = 1;
    for(int i=1;i<=n;i++)
        fac[i] = mult(fac[i-1],i);

    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
        C1[i][j] = C(i,j);

    printf("%d\n",solve(1,0,0));
}       

Compilation message

zapina.cpp: In function 'int main()':
zapina.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1644 KB Output is correct
2 Correct 1 ms 1644 KB Output is correct
3 Correct 1 ms 1644 KB Output is correct
4 Correct 1 ms 1644 KB Output is correct
5 Correct 1 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1644 KB Output is correct
2 Correct 1 ms 1644 KB Output is correct
3 Correct 1 ms 1644 KB Output is correct
4 Correct 1 ms 1644 KB Output is correct
5 Correct 1 ms 1644 KB Output is correct
6 Correct 2 ms 1644 KB Output is correct
7 Correct 1 ms 1644 KB Output is correct
8 Correct 1 ms 1644 KB Output is correct
9 Correct 1 ms 1644 KB Output is correct
10 Correct 1 ms 1644 KB Output is correct
11 Correct 2 ms 1644 KB Output is correct
12 Correct 1 ms 1644 KB Output is correct
13 Correct 1 ms 1644 KB Output is correct
14 Correct 2 ms 1644 KB Output is correct
15 Correct 2 ms 1644 KB Output is correct
16 Correct 2 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1644 KB Output is correct
2 Correct 1 ms 1644 KB Output is correct
3 Correct 1 ms 1644 KB Output is correct
4 Correct 1 ms 1644 KB Output is correct
5 Correct 1 ms 1644 KB Output is correct
6 Correct 2 ms 1644 KB Output is correct
7 Correct 1 ms 1644 KB Output is correct
8 Correct 1 ms 1644 KB Output is correct
9 Correct 1 ms 1644 KB Output is correct
10 Correct 1 ms 1644 KB Output is correct
11 Correct 2 ms 1644 KB Output is correct
12 Correct 1 ms 1644 KB Output is correct
13 Correct 1 ms 1644 KB Output is correct
14 Correct 2 ms 1644 KB Output is correct
15 Correct 2 ms 1644 KB Output is correct
16 Correct 2 ms 1644 KB Output is correct
17 Correct 423 ms 2160 KB Output is correct
18 Correct 5 ms 1772 KB Output is correct
19 Correct 95 ms 2028 KB Output is correct
20 Correct 2 ms 1644 KB Output is correct
21 Correct 561 ms 2156 KB Output is correct
22 Correct 67 ms 2028 KB Output is correct
23 Correct 8 ms 1772 KB Output is correct
24 Correct 124 ms 1900 KB Output is correct
25 Correct 85 ms 1900 KB Output is correct
26 Correct 167 ms 2028 KB Output is correct
27 Correct 793 ms 2284 KB Output is correct
28 Correct 807 ms 2412 KB Output is correct
29 Correct 807 ms 2284 KB Output is correct
30 Correct 822 ms 2284 KB Output is correct
31 Correct 819 ms 2280 KB Output is correct
32 Correct 832 ms 2284 KB Output is correct
33 Correct 839 ms 2284 KB Output is correct
34 Correct 844 ms 2284 KB Output is correct
35 Correct 852 ms 2540 KB Output is correct
36 Correct 860 ms 2288 KB Output is correct
37 Correct 865 ms 2412 KB Output is correct