답안 #1025137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025137 2024-07-16T16:24:53 Z cnn008 Zapina (COCI20_zapina) C++17
110 / 110
202 ms 2988 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef N_N_C
#include "debug.h"
#else
#define cebug(...) "Arya"
#endif

#define int long long

const int N=400;
const int mod=1e9+7;

int n,dp[N][N][2],f[N],inv[N];
int powmod(int a, int k, int m){
   	int ans=1;
    while(k){
        if(k&1) ans=(ans*a)%m;
        a=(a*a)%m;
        k>>=1;
    }
    return ans;
}
int C(int n, int k){
	if(n<k) return 0;
	return f[n]*inv[k]%mod*inv[n-k]%mod;
}
int cal(int i, int task, bool ayase){
	if(i==n+1) return ((!task)&(ayase));
	if(dp[i][task][ayase]!=-1) return dp[i][task][ayase];
	if(!task) return dp[i][task][ayase]=ayase;
	if(ayase) return dp[i][task][ayase]=powmod(n-i+1,task,mod);
	dp[i][task][ayase]=0;
	for(int j=0; j<=task; j++) dp[i][task][ayase]=(dp[i][task][ayase]+((cal(i+1,task-j,j==i)*C(task,j))%mod))%mod;
	return dp[i][task][ayase];
}
void sol(){
	cin>>n;
	if(n==1){
		cout<<1;
		return;
	}
	if(n==2){
		cout<<3;
		return;
	}
	f[0]=1;
	for(int i=1; i<=350; i++) f[i]=(f[i-1]*i)%mod;
	inv[0]=1;
	for(int i=1; i<=350; i++) inv[i]=powmod(f[i],mod-2,mod);
	memset(dp,-1,sizeof(dp));
	cout<<cal(1,n,0);
}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen(".inp", "r", stdin);
    // freopen(".out", "w", stdout);
    int tt=1;
    //cin>>tt; 
    while(tt--){
    	sol();
    }
    cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    return 0;
}
/**  /\_/\
*   (= ._.)
*   / >💖 \>💕
**/

Compilation message

zapina.cpp:68:9: warning: "/*" within comment [-Wcomment]
   68 | /**  /\_/\
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 1 ms 2772 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 2 ms 2968 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 1 ms 2772 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 2 ms 2968 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 97 ms 2904 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 22 ms 2732 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 132 ms 2972 KB Output is correct
22 Correct 15 ms 2908 KB Output is correct
23 Correct 3 ms 2904 KB Output is correct
24 Correct 28 ms 2984 KB Output is correct
25 Correct 20 ms 2908 KB Output is correct
26 Correct 38 ms 2908 KB Output is correct
27 Correct 183 ms 2908 KB Output is correct
28 Correct 194 ms 2988 KB Output is correct
29 Correct 184 ms 2908 KB Output is correct
30 Correct 189 ms 2908 KB Output is correct
31 Correct 198 ms 2908 KB Output is correct
32 Correct 200 ms 2904 KB Output is correct
33 Correct 189 ms 2976 KB Output is correct
34 Correct 192 ms 2904 KB Output is correct
35 Correct 193 ms 2908 KB Output is correct
36 Correct 195 ms 2768 KB Output is correct
37 Correct 202 ms 2904 KB Output is correct