fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6. using ll = long long;
  7.  
  8. ll solve(ll N, ll K, ll L) {
  9. // If there's only one square
  10. if (N == 1) {
  11. return 4LL * L * L;
  12. }
  13.  
  14. // If squares don't overlap (K > 2L)
  15. if (K > 2 * L) {
  16. return N * 4LL * L * L;
  17. }
  18.  
  19. // Calculate the area for overlapping squares
  20. // The width of each square is 2L
  21. ll sideLength = 2 * L;
  22.  
  23. // Calculate the total span
  24. ll totalSpan = (N - 1) * K + 2 * L;
  25.  
  26. // The area will be totalSpan × totalSpan
  27. return totalSpan * totalSpan;
  28. }
  29.  
  30. int main() {
  31. ios_base::sync_with_stdio(false);
  32. cin.tie(NULL);
  33.  
  34. ll N, K, L;
  35. cin >> N >> K >> L;
  36.  
  37. cout << solve(N, K, L) << "\n";
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5292KB
stdin
4 1 2
stdout
49