Submission #900595

#TimeUsernameProblemLanguageResultExecution timeMemory
900595warner1129Kangaroo (CEOI16_kangaroo)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); } #define debug(x...) dbg(#x, '=', x, '\n') #else #define debug(...) ((void)0) #endif #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define ff first #define ss second using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128; using u128 = unsigned __int128; template<class T> inline constexpr T inf = numeric_limits<T>::max() / 2; constexpr int mod = 1e9 + 7, inv2 = (mod + 1) / 2; template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); } template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); } void solve() { int n, s, t; cin >> n >> s >> t; bool op = s > 1; bool ed = t > 1; vector dp(n + 1, array<array<i64, 2>, 2>{}); dp[1][0][0] = 1; for (int i = 2; i <= n; i++) { decltype(dp) f(n + 1); // vector<i64> f(n + 1); for (int j = 1; j < i; j++) { if (i == s) { f[j][0][0] += dp[j][0][0]; f[j][0][1] += dp[j][0][1]; } else if (i == t) { f[j][0][0] += dp[j][0][0]; f[j][1][0] += dp[j][1][0]; } else { for (int x : {0, 1}) for (int y : {0, 1}) { f[j - 1][x][y] += dp[j][x][y] * (j - 1); f[j + 1][x][y] += dp[j][x][y] * (i - 1 - j + op + ed); if (!op) f[j + x][x ^ 1][y] += dp[j][x][y]; if (!ed) f[j + y][x][y ^ 1] += dp[j][x][y]; } } } if (s == i) op = false; if (t == i) ed = false; dp.swap(f); for (int j = 0; j <= n; j++) for (int x : {0, 1}) for (int y : {0, 1}) dp[j][x][y] %= mod; } cout << (dp[1][0][0] + dp[1][0][1] + dp[1][1][0] + dp[1][1][1]) << '\n'; } signed main() { cin.tie(0)->sync_with_stdio(false); cin.exceptions(cin.failbit); int T = 1; // cin >> T; while (T--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...