Submission #523738

#TimeUsernameProblemLanguageResultExecution timeMemory
523738LptN21Kangaroo (CEOI16_kangaroo)C++14
100 / 100
38 ms15964 KiB
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL); #define PI acos(-1.0) #define eps 1e-9 #define FF first #define SS second // VECTOR (6) #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() ); // BIT (6) #define CNTBIT(x) __builtin_popcountll(x) #define ODDBIT(x) __builtin_parityll(x) #define MASK(i) (1LL<<(i)) #define BIT(x, i) (((x)>>(i))&1) #define SUBSET(big, small) (((big)&(small))==(small)) #define FIRSTBIT(x) __builtin_ctzll(x) //typedef typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> ii; /* */ template<class T> bool minimize(T &a, const T &b) { if(a > b) {a = b; return 1;} return 0; } template<class T> bool maximize(T &a, const T &b) { if(a < b) {a = b; return 1;} return 0; } /* */ /* CODE BELOW */ const int N = 2e3 + 7, M = 1e9 + 7; const int oo = 1e9 + 7; const int MOD = 1e9 + 7; int n, cs, cf; int _dp[N][N]; int add(int a, int b) { a+= b; if(a>=MOD) a-=MOD; return a; } int mul(int a, int b) { return (1LL * a * b)%MOD; } void update(int &a, int b) { a+= b; if(a>=MOD) a-=MOD; } signed main() { //freopen("test.inp", "r", stdin); //freopen("test.out", "w", stdout); //fastIO; scanf("%d%d%d", &n, &cs, &cf); _dp[1][1] = 1; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(i == cs || i == cf) { update(_dp[i][j], add(_dp[i-1][j-1], _dp[i-1][j])); // create new component // make it an endpoint of left/right component (based on whether it is cs of cf) continue; } update(_dp[i][j], mul(_dp[i-1][j-1], j - (i > cs) - (i > cf))); // create new component update(_dp[i][j], mul(_dp[i-1][j+1], j)); // connect 2 existing component } } printf("%d", _dp[n][1]); return 0; }

Compilation message (stderr)

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     scanf("%d%d%d", &n, &cs, &cf);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...