Submission #353535

#TimeUsernameProblemLanguageResultExecution timeMemory
353535shivensinha4Tents (JOI18_tents)C++17
48 / 100
659 ms213740 KiB
#include "bits/stdc++.h" using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' const ll mod = 1e9+7; ll ncr(ll n, ll r) { if (r == 0) return 1; if (r == 1) return n; if (r == 2) return ((n*(n-1))/2 % mod); assert(false); } int main() { #ifdef mlocal freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; ll dp[n+1][m+1][m+1]; // [row][empty][light] memset(dp, 0, sizeof(dp)); vector<ll> tp(m+1); tp[0] = 1; for_(i, 1, tp.size()) tp[i] = (4*tp[i-1]) % mod; for_(i, 0, m+1) for_(j, 0, m+1) if (j+i <= m) dp[n][i][j] = tp[j]; for (int i = n-1; i >= 0; i--) { // cout << i << ": " << endl; for_(emp, 0, m+1) for_(lt, 0, m+1) if (emp+lt <= m) { for_(empTake, 0, min(emp, 2)+1) for_(ltTake, 0, min(lt, 1)+1) { if ((ltTake and empTake)) continue; dp[i][emp][lt] += (((ncr(emp, empTake) * ncr(lt, ltTake)) % mod) * dp[i+1][emp-empTake][lt-ltTake+(empTake == 2 ? 0 : empTake)]) % mod; if (dp[i][emp][lt] >= mod) dp[i][emp][lt] -= mod; } // cout << "empty: " << emp << " light: " << lt << " -> " << dp[i][emp][lt] << endl; } } cout << (dp[0][m][0]-1+mod) % mod << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...