cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

two_knights_1072.cpp (471B)


      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 }