Submission #857385

# Submission time Handle Problem Language Result Execution time Memory
857385 2023-10-06T04:47:29 Z MilosMilutinovic Zapina (COCI20_zapina) C++14
110 / 110
285 ms 1768 KB
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=1e9+7;
int fct[355],inv[355];
void ckadd(int& x,int y){ x+=y; if(x>=cys) x-=cys; }
int ckmul(int x,int y){ return (1ll*x*y)%cys; }
int ckpow(int a,int b) { int res=1; for(;b;b>>=1,a=ckmul(a,a)){ if(b&1) res=ckmul(res,a); } return res; }
int C(int x,int y){ return ckmul(fct[x],ckmul(inv[y],inv[x-y])); }
void init(){
	fct[0]=1;
	for(int i=1;i<=350;i++) fct[i]=ckmul(fct[i-1],i);
	inv[350]=ckpow(fct[350],cys-2);
	for(int i=349;i>=0;i--) inv[i]=ckmul(inv[i+1],i+1);
}

int dp[355][355][2];

int main(){
	init();
	int n=readint();
	dp[0][0][0]=1;
	for(int i=1;i<=n;i++){
		for(int x=0;x<=n;x++){
			for(int f=0;f<2;f++){
				for(int y=0;x+y<=n;y++){
					int nf=(f|(y==i));
					ckadd(dp[i][x+y][nf],ckmul(C(n-x,y),dp[i-1][x][f]));
				}
			}	
		}
	}
	printf("%d\n",dp[n][n][1]);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 137 ms 1008 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 29 ms 672 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 179 ms 1112 KB Output is correct
22 Correct 20 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 38 ms 732 KB Output is correct
25 Correct 26 ms 792 KB Output is correct
26 Correct 52 ms 848 KB Output is correct
27 Correct 285 ms 1340 KB Output is correct
28 Correct 258 ms 1168 KB Output is correct
29 Correct 262 ms 1288 KB Output is correct
30 Correct 263 ms 1364 KB Output is correct
31 Correct 264 ms 1768 KB Output is correct
32 Correct 264 ms 1212 KB Output is correct
33 Correct 266 ms 1364 KB Output is correct
34 Correct 276 ms 1184 KB Output is correct
35 Correct 281 ms 1232 KB Output is correct
36 Correct 276 ms 1368 KB Output is correct
37 Correct 276 ms 1292 KB Output is correct