Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f6b3e3b

Browse files
Create Knight Explanation.txt
1 parent fe2e02b commit f6b3e3b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Firstly, the constraints are too big to do a DP.
2+
3+
1. Let us notice the sum (i, j) (mod 3) is an invariant at each step.
4+
5+
Initially it is 0. So, if (X + Y) = 0 (mod 3), we can reach (X, Y). Otherwise, no.
6+
7+
2. Now, let us suppose that we make R moves of the kind (i + 1, j + 2) and D moves of the kind (i + 2, j + 1).
8+
9+
Then,
10+
11+
R + 2D = X
12+
2R + D = Y
13+
14+
Since we know the values of X and Y, let us try to write (D, R) in terms of (X, Y)
15+
16+
2X - Y = 3D
17+
2Y - X = 3R
18+
19+
3. Now that we know the values of (D, R), we need to count the number of strings of length (D + R) with D d's and R r's. This string is uniquely determined by the placement of the d's or the r's.
20+
21+
So, the answer = C(D + R, D) = C(D + R, R)
22+
23+
Or course, both D and R have to be > 0
24+
25+
-----
26+
27+
int main()
28+
{
29+
int X, Y;
30+
cin >> X >> Y;
31+
32+
if( (X + Y)%3 != 0)
33+
{
34+
cout << "0\n";
35+
36+
return 0;
37+
}
38+
39+
long long D = (2*Y - X)/3;
40+
long long L = (2*X - Y)/3;
41+
42+
const int MOD = 1e9 + 7;
43+
cout << ( (D < 0 || L < 0) ? 0 : combinations(D + L, D, MOD) );
44+
45+
return 0;
46+
}
47+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /