# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116324 | emilem | Treasure (different grader from official contest) (CEOI13_treasure2) | C++14 | 2 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "treasure.h"
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
typedef std::tuple<int, int, int, int> Arguments;
static int n = 0;
int CountTreasures(int minI, int maxI, int minJ, int maxJ)
{
if (minI < 0 || minJ < 0 || maxI >= n || maxJ >= n)
return 0;
static std::map<Arguments, int> cache;
Arguments curArguments(minI, maxI, minJ, maxJ);
if (cache.find(curArguments) != cache.end())
return cache.at(curArguments);
int ans = countTreasure(minI + 1, minJ + 1, maxI + 1, maxJ + 1);
cache.insert(std::make_pair(curArguments, ans));
return ans;
}
inline int CountTreasures(const Arguments& arg)
{
return CountTreasures(std::get<0>(arg), std::get<1>(arg), std::get<2>(arg), std::get<3>(arg));
}
Arguments make_Arguments(const std::pair<int, int>& IArguments, const std::pair<int, int>& JArguments)
{
return Arguments(IArguments.first, IArguments.second, JArguments.first, JArguments.second);
}
void findTreasure(int N)
{
n = N;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
{
int iDir, jDir;
iDir = (i + 1 >= n - i) ? -1 : 1;
jDir = (j + 1 >= n - j) ? -1 : 1;
std::pair<int, int> iArg, iLessArg, jArg, jLessArg;
if (iDir == -1) { iArg = std::make_pair(0, i); iLessArg = std::make_pair(0, i - 1); }
else { iArg = std::make_pair(i, n - 1); iLessArg = std::make_pair(i + 1, n - 1); }
if (jDir == -1) {jArg = std::make_pair(0, j); jLessArg = std::make_pair(0, j - 1); }
else {jArg = std::make_pair(j, n - 1); jLessArg = std::make_pair(j + 1, n - 1); }
int count = CountTreasures(make_Arguments(iArg, jArg)) -
CountTreasures(make_Arguments(iLessArg, jArg)) - CountTreasures(make_Arguments(iArg, jLessArg)) +
CountTreasures(make_Arguments(iLessArg, jLessArg));
if (count)
Report(i + 1, j + 1);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |