#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 2005;
int N,cs,cf;
int A[MX][MX], a[MX][MX];
int AA[MX][MX], aa[MX][MX];
int D[MX][MX], d[MX][MX];
int ad(int a, int b) { return (a+b)%MOD; }
int sub(int a, int b) { return (a-b+MOD)%MOD; }
int getD(int n, int i, int j);
int getA(int n, int i, int j) { // what about getA(n,0,j)?
if (i == j || i < 0 || i > n-1 || j < 0 || j > n-1) return 0;
if (i == 0) {
if (aa[n][j]) return AA[n][j];
aa[n][j] = 1;
if (j == 1) {
if (n == 2) AA[n][j] = 1;
else if (n % 2 == 0) AA[n][j] = 0;
else {
FOR(i,1,n-1) AA[n][j] = ad(AA[n][j],getA(n-1,0,i));
}
} else {
if (n % 2 == 1) AA[n][j] = sub(getA(n,0,j-1),getA(n-1,0,j-1));
else AA[n][j] = ad(getA(n,0,j-1),getA(n-1,0,j-1));
}
// cout << "A " << n << " " << i << " " << j << " " << AA[n][j] << "\n";
return AA[n][j];
}
if (a[i][j]) return A[i][j];
a[i][j] = 1;
A[i][j] = sub(getA(n,i-1,j),getD(n-1,i-1,j-1));
// cout << "A " << n << " " << i << " " << j << " " << A[i][j] << " " << getA(n,i-1,j) << " " << getD(n-1,i-1,j-1) << "\n";
return A[i][j];
}
int getD(int n, int i, int j) {
if (i == j || i <= 0 || i > n-1 || j < 0 || j > n-1) return 0;
if (d[i][j]) return D[i][j];
d[i][j] = 1;
D[i][j] = ad(getD(n,i-1,j),getA(n-1,i-1,j-1));
// cout << "D " << n << " " << i << " " << j << " " << D[i][j] << "\n";
return D[i][j];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> cs >> cf;
if (cs > cf) swap(cs,cf);
cs --, cf --;
// cout << getA(N,cs,cf) << " " << getD(N,cs,cf) << "\n";
cout << ad(getA(N,cs,cf),getD(N,cs,cf));
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
644 KB |
Output is correct |
3 |
Correct |
3 ms |
992 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
3 ms |
1648 KB |
Output is correct |
6 |
Correct |
3 ms |
1648 KB |
Output is correct |
7 |
Correct |
3 ms |
1648 KB |
Output is correct |
8 |
Correct |
3 ms |
1648 KB |
Output is correct |
9 |
Correct |
3 ms |
1648 KB |
Output is correct |
10 |
Correct |
4 ms |
1648 KB |
Output is correct |
11 |
Correct |
4 ms |
1652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
644 KB |
Output is correct |
3 |
Correct |
3 ms |
992 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
3 ms |
1648 KB |
Output is correct |
6 |
Correct |
3 ms |
1648 KB |
Output is correct |
7 |
Correct |
3 ms |
1648 KB |
Output is correct |
8 |
Correct |
3 ms |
1648 KB |
Output is correct |
9 |
Correct |
3 ms |
1648 KB |
Output is correct |
10 |
Correct |
4 ms |
1648 KB |
Output is correct |
11 |
Correct |
4 ms |
1652 KB |
Output is correct |
12 |
Correct |
8 ms |
3704 KB |
Output is correct |
13 |
Correct |
5 ms |
3704 KB |
Output is correct |
14 |
Correct |
11 ms |
6144 KB |
Output is correct |
15 |
Correct |
5 ms |
6144 KB |
Output is correct |
16 |
Correct |
7 ms |
6144 KB |
Output is correct |
17 |
Correct |
7 ms |
6144 KB |
Output is correct |
18 |
Correct |
5 ms |
6144 KB |
Output is correct |
19 |
Correct |
6 ms |
6144 KB |
Output is correct |
20 |
Correct |
6 ms |
6144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
644 KB |
Output is correct |
3 |
Correct |
3 ms |
992 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
3 ms |
1648 KB |
Output is correct |
6 |
Correct |
3 ms |
1648 KB |
Output is correct |
7 |
Correct |
3 ms |
1648 KB |
Output is correct |
8 |
Correct |
3 ms |
1648 KB |
Output is correct |
9 |
Correct |
3 ms |
1648 KB |
Output is correct |
10 |
Correct |
4 ms |
1648 KB |
Output is correct |
11 |
Correct |
4 ms |
1652 KB |
Output is correct |
12 |
Correct |
8 ms |
3704 KB |
Output is correct |
13 |
Correct |
5 ms |
3704 KB |
Output is correct |
14 |
Correct |
11 ms |
6144 KB |
Output is correct |
15 |
Correct |
5 ms |
6144 KB |
Output is correct |
16 |
Correct |
7 ms |
6144 KB |
Output is correct |
17 |
Correct |
7 ms |
6144 KB |
Output is correct |
18 |
Correct |
5 ms |
6144 KB |
Output is correct |
19 |
Correct |
6 ms |
6144 KB |
Output is correct |
20 |
Correct |
6 ms |
6144 KB |
Output is correct |
21 |
Correct |
16 ms |
10788 KB |
Output is correct |
22 |
Correct |
17 ms |
12076 KB |
Output is correct |
23 |
Correct |
19 ms |
12076 KB |
Output is correct |
24 |
Correct |
85 ms |
38572 KB |
Output is correct |
25 |
Correct |
145 ms |
52456 KB |
Output is correct |
26 |
Correct |
100 ms |
52456 KB |
Output is correct |
27 |
Correct |
72 ms |
52456 KB |
Output is correct |
28 |
Correct |
52 ms |
52456 KB |
Output is correct |