Submission #201071

# Submission time Handle Problem Language Result Execution time Memory
201071 2020-02-09T09:36:10 Z mraron Zapina (COCI20_zapina) C++14
110 / 110
170 ms 1400 KB
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


const ll mod=1e9+7;
ll dp[351][351];
ll f[351];
ll inv[351];

ll fp(ll a, ll b) {
	if(b==0) return 1;
	ll fel=fp(a,b/2);
	ll ans=fel*fel%mod;
	if(b&1) ans=(ans*a)%mod;
	return ans;
}

ll nc(ll a, ll b) {
	return f[a]*inv[b]%mod*inv[a-b]%mod;
}


int main() {
	IO;
	f[0]=1;
	for(int i=1;i<351;++i) f[i]=f[i-1]*i%mod;
	for(int i=0;i<351;++i) inv[i]=fp(f[i],mod-2);
	
	ll n;
	cin>>n;
	dp[0][n]=1;
	for(int i=1;i<=n;++i) {
		for(int j=0;j<=n;++j) {
			for(int k=0;k<=j;++k) {
				if(k==i) continue ;
				dp[i][j-k]+=dp[i-1][j]*nc(j,k);
				dp[i][j-k]%=mod;
			}
		}
	}
	ll res=(fp(n,n)-dp[n][0])%mod;
	if(res<0) res+=mod;
	cout<<res<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 80 ms 1144 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 21 ms 760 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 105 ms 1144 KB Output is correct
22 Correct 16 ms 764 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 26 ms 888 KB Output is correct
25 Correct 19 ms 760 KB Output is correct
26 Correct 32 ms 888 KB Output is correct
27 Correct 147 ms 1400 KB Output is correct
28 Correct 147 ms 1300 KB Output is correct
29 Correct 148 ms 1316 KB Output is correct
30 Correct 153 ms 1272 KB Output is correct
31 Correct 150 ms 1400 KB Output is correct
32 Correct 157 ms 1276 KB Output is correct
33 Correct 157 ms 1300 KB Output is correct
34 Correct 150 ms 1272 KB Output is correct
35 Correct 170 ms 1332 KB Output is correct
36 Correct 158 ms 1276 KB Output is correct
37 Correct 157 ms 1272 KB Output is correct