#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 2e3 + 9;
const ll Log2 = 20;
const ll mod = 1e9 + 7;
ll n,s,e,dp[N][N];
ll f(ll pos,ll g){
if (pos == n + 1) return !g;
if (dp[pos][g] != -1) return dp[pos][g];
ll ans = 0;
if (pos > e){
if (g) ans = f(pos + 1,g - 1);
ans = (ans + f(pos + 1,g + 1) * g * (g + 1))%mod;
}
else if (pos == e) ans = (f(pos + 1,g) + f(pos + 1,g + 1)*(g + 1))%mod;
else if (pos > s){
if (g) ans = f(pos + 1,g - 1);
ans = (ans + f(pos + 1,g + 1) * (g + 1) * (g + 1))%mod;
}
else if (pos == s) ans = (f(pos + 1,g) + f(pos + 1,g + 1)*(g + 1))%mod;
else if (pos < s){
if (g) ans = f(pos + 1,g - 1);
ans = (ans + f(pos + 1,g + 1) * (g + 2) * (g + 1))%mod;
}
return dp[pos][g] = ans;
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>s>>e; memset(dp,-1,sizeof(dp));
cout<<f(2,0);
}
Compilation message
kangaroo.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization O2
|
kangaroo.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
kangaroo.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
3 | #pragma target ("avx2")
|
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31820 KB |
Output is correct |
2 |
Correct |
16 ms |
31832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31820 KB |
Output is correct |
2 |
Correct |
16 ms |
31832 KB |
Output is correct |
3 |
Correct |
17 ms |
31820 KB |
Output is correct |
4 |
Correct |
17 ms |
31784 KB |
Output is correct |
5 |
Correct |
19 ms |
31820 KB |
Output is correct |
6 |
Correct |
17 ms |
31860 KB |
Output is correct |
7 |
Incorrect |
17 ms |
31820 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31820 KB |
Output is correct |
2 |
Correct |
16 ms |
31832 KB |
Output is correct |
3 |
Correct |
17 ms |
31820 KB |
Output is correct |
4 |
Correct |
17 ms |
31784 KB |
Output is correct |
5 |
Correct |
19 ms |
31820 KB |
Output is correct |
6 |
Correct |
17 ms |
31860 KB |
Output is correct |
7 |
Incorrect |
17 ms |
31820 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31820 KB |
Output is correct |
2 |
Correct |
16 ms |
31832 KB |
Output is correct |
3 |
Correct |
17 ms |
31820 KB |
Output is correct |
4 |
Correct |
17 ms |
31784 KB |
Output is correct |
5 |
Correct |
19 ms |
31820 KB |
Output is correct |
6 |
Correct |
17 ms |
31860 KB |
Output is correct |
7 |
Incorrect |
17 ms |
31820 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |