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
data Payment = Payment | |
{ amount :: Money | |
, from :: Account | |
, to :: Account | |
} |
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
/** | |
* Example: | |
* - Grades: 2 4 2 6 1 7 8 9 2 1 | |
* - Candies: 1 2 1 2 1 2 3 4 2 1 | |
* | |
* Look for the longest strictly increasing & decreasing sequence? | |
*/ | |
long long min_candies(std::vector<long long> const& grades) | |
{ | |
int n = grades.size(); |
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
import qualified Data.Vector as V | |
main :: IO () | |
main = do | |
n <- readLn | |
replicateM_ n $ do | |
(n, m) <- readMatrix | |
print (bestQuadrant n m) | |
type Matrix = V.Vector (V.Vector Int) |
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
int best_quadrant(Matrix const& m) | |
{ | |
int n = m.size() / 2; | |
return accumulate(range(0, n) * range(0, n), 0, [&](int sum, Coord const& coord){ | |
auto flips = symetric_values(m, n, coord); | |
return sum + *std::max_element(flips.begin(), flips.end()); | |
}); | |
} |
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
int best_quadrant(Matrix const& m) | |
{ | |
int n = m.size() / 2; | |
return accumulate(range(0, n), 0, [&](int sum, int i){ | |
return accumulate(range(0, n), sum, [&](int sum, int j){ | |
auto flips = symetric_values(m, n, {i, j}); | |
return sum + *std::max_element(flips.begin(), flips.end()); | |
}); | |
}); | |
} |
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
int best_quadrant(Matrix const& m) | |
{ | |
int n = m.size() / 2; | |
int sum = 0; | |
for (int i : range(0, n)) | |
{ | |
for (int j : range(0, n)) | |
{ | |
auto flips = symetric_values(m, n, {i, j}); | |
sum += *std::max_element(flips.begin(), flips.end()); |
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
template<typename ValueType> | |
class next_iterator | |
: public std::iterator<std::forward_iterator_tag, ValueType> | |
{ | |
public: | |
next_iterator(ValueType current) : m_current(std::move(current)) {} | |
next_iterator(next_iterator const&) = default; | |
friend bool operator== (next_iterator const& lhs, next_iterator const& rhs) | |
{ |
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
using Coord = std::pair<int, int>; | |
using Matrix = std::vector<vector<int>>; | |
int read_int() | |
{ | |
int i; | |
std::cin >> i; | |
return i; | |
} |
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
using Coord = std::pair<int, int>; | |
using Matrix = std::vector<vector<int>>; | |
int read_int() | |
{ | |
int n; | |
std::cin >> n; | |
return n; | |
} |
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
within(sqrt_roots(2.0), 1e-6) | |
> 1.41421356237 |