(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #376613

#TimeUsernameProblemLanguageResultExecution timeMemory
376613MatheusLealVKangaroo (CEOI16_kangaroo)C++17
100 / 100
59 ms32140 KiB
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define mp make_pair #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define rep(i, a, b) for (int i = (a); i < (b); ++i) std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count()); using namespace std; // #define int long long typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; ll mod = (1000000007LL); inline ll Mod(ll a, ll b){return (a%b);} inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;} ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;} void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];} void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}} int prodmod(vector<int> w); int summod(vector<int> w); ///CUIDADO COM MAXN #define N 2010 int n, ini, fim; ll dp[N][N]; ll solve(int i, int k){ if(k < 0) return 0; if(i > n) return (k==1); if(dp[i][k] != -1) return dp[i][k]; int ans = 0; if(i == ini or i == fim){ ll newcomp = solve(i+1,k+1); ll ponta = solve(i+1,k); return dp[i][k] = (newcomp + ponta)%mod; } if(i > fim){ ll newcomp = 1LL*solve(i + 1, k + 1)*(k-1); ll merge = 1LL*solve(i+1,k-1)*(k-1); return dp[i][k] = (newcomp + merge)%mod; } if(i > ini){ ll newcomp = 1LL*solve(i+1,k+1)*k; ll merge = 1LL*solve(i+1, k -1)*(k-1); return dp[i][k] = (newcomp + merge)%mod; } ll newcomp = 1LL*solve(i+1,k+1)*(k+1); ll merge = 1LL*solve(i+1,k-1)*(k-1); return dp[i][k] = (newcomp + merge)%mod; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n>>ini>>fim; if(ini>fim)swap(ini, fim); memset(dp,-1,sizeof dp); cout<<solve(1, 0)<<"\n"; } /* CUIDADO COM MAXN, MOD, OVERFLOW >Colocar (>DEFINE INT LONG LONG<) no inicio do template >mod = (1e9 + 7), por padrao (NAO ESQUECER DE ALTERAR) >NAO ESQUECER DEFINE INT LONG LONG > N = 1 ? */ int summod(vector<int> w){int curr=0;for(int i=0;i<sz(w); i++){curr = (curr+w[i])%mod;if(curr<0)curr+=mod;}return curr;} int prodmod(vector<int> w){int curr = 1; for(int i = 0; i < sz(w); i++){if(w[i] >= mod) w[i] %= mod;curr = (curr * w[i]) % mod;if(curr < 0) curr += mod;}return curr;}

Compilation message (stderr)

kangaroo.cpp: In function 'll solve(int, int)':
kangaroo.cpp:33:6: warning: unused variable 'ans' [-Wunused-variable]
   33 |  int ans = 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...