제출 #116325

#제출 시각아이디문제언어결과실행 시간메모리
116325emilem보물 찾기 (CEOI13_treasure2)C++14
80 / 100
15 ms1168 KiB
#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)); } 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); } }

컴파일 시 표준 에러 (stderr) 메시지

treasure.cpp: In function 'void findTreasure(int)':
treasure.cpp:43:8: warning: unused variable 'count' [-Wunused-variable]
    int count = CountTreasures(make_Arguments(iArg, jArg)) -
        ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...