답안 #637452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637452 2022-09-01T20:21:17 Z vovamr Zapina (COCI20_zapina) C++17
110 / 110
154 ms 1908 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }

constexpr int md = 1e9 + 7; constexpr int iv2 = (md + 1) / 2;
inline int add(int a, int b) { if((a+=b)>=md)a-=md; return a; }
inline int sub(int a, int b) { if((a-=b)<0)a+=md; return a; }
inline int mul(int a, int b) { return 1ll*a*b%md; }
inline int bp(int a, int n) { int res = 1;
	for (; n; n >>= 1, a = mul(a, a)) {
		if (n & 1) res = mul(res, a);
	} return res;
}
inline int inv(int a) { return bp(a, md - 2); }

const int N = 353;
int dp[N][N][2];
int c[N][N];

inline void solve() {
	int n;
	cin >> n;

	for (int i = 0; i <= n; ++i) {
		c[i][0] = 1;
		for (int j = 1; j <= i; ++j) {
			c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]);
		}
	}

	dp[0][0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int have = 0; have <= n; ++have) {
			for (int fl : {0, 1}) {
				if (!dp[i][have][fl]) continue;
				for (int take = 0; have + take <= n; ++take) {
					int &f = dp[i + 1][have + take][fl | (i + 1 == take)];
					f = add(f, mul(dp[i][have][fl], c[n - have][take]));
				}
			}
		}
	}

	cout << dp[n][n][1];
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 356 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 356 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 73 ms 1468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 16 ms 960 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 97 ms 1448 KB Output is correct
22 Correct 11 ms 904 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 21 ms 968 KB Output is correct
25 Correct 15 ms 904 KB Output is correct
26 Correct 28 ms 1036 KB Output is correct
27 Correct 137 ms 1668 KB Output is correct
28 Correct 136 ms 1612 KB Output is correct
29 Correct 138 ms 1832 KB Output is correct
30 Correct 142 ms 1908 KB Output is correct
31 Correct 140 ms 1708 KB Output is correct
32 Correct 148 ms 1668 KB Output is correct
33 Correct 144 ms 1816 KB Output is correct
34 Correct 147 ms 1860 KB Output is correct
35 Correct 149 ms 1740 KB Output is correct
36 Correct 154 ms 1728 KB Output is correct
37 Correct 151 ms 1732 KB Output is correct