diff options
Diffstat (limited to '')
| -rw-r--r-- | 01_introductory_problems/two_knights_1072.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/01_introductory_problems/two_knights_1072.cpp b/01_introductory_problems/two_knights_1072.cpp new file mode 100644 index 0000000..15d5f55 --- /dev/null +++ b/01_introductory_problems/two_knights_1072.cpp | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <vector> | ||
| 3 | |||
| 4 | int main() { | ||
| 5 | long long n, a; | ||
| 6 | std::vector<long long> b = {0, 0, 6, 28, 96}; | ||
| 7 | std::cin >> n; | ||
| 8 | |||
| 9 | for (long long k = 1; k <= n; k++) { | ||
| 10 | if (k <= 4) { | ||
| 11 | a = b[k]; | ||
| 12 | } else { | ||
| 13 | // Both knights in new strip | ||
| 14 | a += (2*k - 1)*(k - 1) - 2; | ||
| 15 | |||
| 16 | // One knight in new strip, one in previous square | ||
| 17 | const long long s = (k-1)*(k-1); | ||
| 18 | a += 5*(s - 2); | ||
| 19 | a += 4*(s - 3); | ||
| 20 | a += (2*k - 10)*(s - 4); | ||
| 21 | } | ||
| 22 | std::cout << a << std::endl; | ||
| 23 | } | ||
| 24 | } | ||
