Submission #514513

#TimeUsernameProblemLanguageResultExecution timeMemory
514513Killer2501Zapina (COCI20_zapina)C++14
110 / 110
384 ms452 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 4e2+5; const int M = 26; const ll inf = 1e15; const ll mod = 1e9+7; const ld ex = 1e-9; int n, t, k, m, d[N], lab[N]; ll ans, tong, a[N], b[N], c[N], dp[2][N][2], cnt; string s; struct node { int x, y, val; int vx, vy; node(){} node(int _x, int _vx, int _y, int _vy) { x = _x; vx = _vx; y = _y; vy = _vy; } }; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n&1)total = total * k % mod; k = k * k % mod; } return total; } ll C(ll u, ll v) { if(u > v)return 0; return a[v] * b[u] % mod * b[v-u] % mod; } void add(ll& x, ll y) { x += y; if(x >= mod)x -= mod; } void sol() { cin >> n; a[0] = b[0] = 1; for(int i = 1; i <= n; i ++) { a[i] = a[i-1] * i % mod; b[i] = b[i-1] * pw(i, mod-2) % mod; } dp[0][0][0] = 1; for(int i = 0; i < n; i ++) { int nxt = (i&1)^1; memset(dp[nxt], 0, sizeof(dp[nxt])); for(int j = 0; j <= n; j ++) { for(int p = 0; p <= n-j; p ++) { if(p != i+1) { add(dp[nxt][p+j][0], dp[i&1][j][0] * C(p, n-j) % mod); add(dp[nxt][p+j][1], dp[i&1][j][1] * C(p, n-j) % mod); } else { add(dp[nxt][p+j][1], dp[i&1][j][1] * C(p, n-j) % mod); add(dp[nxt][p+j][1], dp[i&1][j][0] * C(p, n-j) % mod); } } } } cout << dp[n&1][n][1]; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); }

Compilation message (stderr)

zapina.cpp: In function 'int main()':
zapina.cpp:93:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zapina.cpp:94:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...