Last active
December 10, 2018 22:32
-
-
Save kraftwerk28/e1ca5f86191f4dc32e4180160a761766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <cstdlib> | |
#include <string> | |
#define let const auto | |
#define CUBE_COUNT 28 | |
using std::cin; | |
using std::cout; | |
using std::endl; | |
using std::string; | |
int main() | |
{ | |
let func = [](uint n) -> int { | |
int ns[3]{0}, swch{0}, cubed{(int)roundf(cbrtf(n * n * n))}; | |
let mall = [&]() -> int { | |
return ns[0] * ns[1] * ns[2]; | |
}; | |
while (mall() < n) | |
{ | |
ns[swch]++; | |
swch = (swch + 1) % 3; | |
} | |
if (mall() != n) | |
{ | |
ns[swch == 0 ? 2 : swch - 1]--; | |
} | |
int | |
a = ns[0], | |
b = ns[1], c = ns[2], | |
res{(a * (b + 1) + b * (a + 1)) * (c + 1) + (b + 1) * (a + 1) * c}, | |
contcnt{0}, | |
max_side = | |
(a >= b && a >= c) ? a : ((b >= a && b >= c) ? b : c); | |
while (mall() + ++contcnt <= n) | |
{ | |
int delta = (contcnt == 1) ? 8 : (((contcnt > 1 && contcnt <= max_side) || (contcnt - 1) % max_side == 0) ? 5 : 3); | |
res += delta; | |
} | |
return res; | |
}; | |
string inp{}; | |
cin >> inp; | |
cout << func(stoi(inp)) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment