Submission #957616

#TimeUsernameProblemLanguageResultExecution timeMemory
957616vjudge1Zapina (COCI20_zapina)C++17
55 / 110
52 ms500 KiB
#include <bits/stdc++.h> #define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define fast_io ios::sync_with_stdio(false);cin.tie(0); #define what(x) cerr << #x << " is " << x << '\n'; #define kill(x) {cout << x << '\n'; return;} #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define pb push_back #define ll long long #define F first #define S second const ll inf = 1e16, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 350, P = 6065621; using namespace std; const int N = 60, LG = 21; ll fac[N], inv[N], pw[N][N]; ll poww (ll a, ll b) { if (!b) return 1; if (b & 1) return a * poww(a * a % mod, b / 2) % mod; return poww(a * a % mod, b / 2); } ll C(int n, int r) { if (r > n || r < 0) return 0; if (r == n || r == 0) return 1; return fac[n] * inv[r] % mod * inv[n - r] % mod; } int main () { fast_io; fac[0] = 1; for (int i = 1; i < N; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = poww(fac[i], mod - 2); } for (int i = 1; i < N; i++) { pw[i][0] = 1; for (int j = 1; j < N; j++) { pw[i][j] = pw[i][j - 1] * i % mod; } } int n; cin >> n; ll ans = 0; for (int mask = 1; mask < (1 << n); mask++) { int tmp = 0; for (int i = 0; i < n; i++) if (mask & (1 << i)) tmp += i + 1; if (tmp > n) continue; int cur = n; ll res = 1; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { res = res * C(cur, i + 1) % mod; cur -= (i + 1); } } int b = __builtin_popcount(mask); if (cur > 0) { res = res * pw[n - b][cur] % mod; } if (b & 1) { ans = (ans + res) % mod; } else { ans -= res; ans += mod; ans %= mod; } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...