#include <iostream> #include <string> #include <unordered_map> #include <algorithm> #include <utility> inline void setupTasksRequirements(std::unordered_map<std::string, int> &map); inline void loadTasks(std::istream &stream, std::unordered_map<std::string, int> &taskMap); inline bool canCreateContest(const std::unordered_map<std::string, int> &map); int main(int argc, char const *argv[]) { std::ios_base::sync_with_stdio(false); // Make stdio fast! std::unordered_map<std::string, int> tasksToPrepare; setupTasksRequirements(tasksToPrepare); loadTasks(std::cin, tasksToPrepare); const std::string answer = canCreateContest(tasksToPrepare) ? "TAK" : "NIE"; std::cout << answer << '\n'; return 0; } inline void loadTasks(std::istream &stream, std::unordered_map<std::string, int> &taskMap) { int n; stream >> n; std::string taskId; while (n--) { stream >> taskId; taskMap[taskId]--; } } inline bool canCreateContest(const std::unordered_map<std::string, int> &map) { auto predicate = [](const std::pair<std::string, int> v) { return v.second <= 0; }; return all_of(map.cbegin(), map.cend(), predicate); } void setupTasksRequirements(std::unordered_map<std::string, int> &map) { map["1A"] = 1; map["1B"] = 1; map["1C"] = 1; map["2A"] = 1; map["2B"] = 1; map["2C"] = 1; map["3A"] = 1; map["3B"] = 1; map["3C"] = 1; map["4A"] = 1; map["4B"] = 1; map["4C"] = 1; map["5A"] = 2; map["5B"] = 2; map["5C"] = 2; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <iostream> #include <string> #include <unordered_map> #include <algorithm> #include <utility> inline void setupTasksRequirements(std::unordered_map<std::string, int> &map); inline void loadTasks(std::istream &stream, std::unordered_map<std::string, int> &taskMap); inline bool canCreateContest(const std::unordered_map<std::string, int> &map); int main(int argc, char const *argv[]) { std::ios_base::sync_with_stdio(false); // Make stdio fast! std::unordered_map<std::string, int> tasksToPrepare; setupTasksRequirements(tasksToPrepare); loadTasks(std::cin, tasksToPrepare); const std::string answer = canCreateContest(tasksToPrepare) ? "TAK" : "NIE"; std::cout << answer << '\n'; return 0; } inline void loadTasks(std::istream &stream, std::unordered_map<std::string, int> &taskMap) { int n; stream >> n; std::string taskId; while (n--) { stream >> taskId; taskMap[taskId]--; } } inline bool canCreateContest(const std::unordered_map<std::string, int> &map) { auto predicate = [](const std::pair<std::string, int> v) { return v.second <= 0; }; return all_of(map.cbegin(), map.cend(), predicate); } void setupTasksRequirements(std::unordered_map<std::string, int> &map) { map["1A"] = 1; map["1B"] = 1; map["1C"] = 1; map["2A"] = 1; map["2B"] = 1; map["2C"] = 1; map["3A"] = 1; map["3B"] = 1; map["3C"] = 1; map["4A"] = 1; map["4B"] = 1; map["4C"] = 1; map["5A"] = 2; map["5B"] = 2; map["5C"] = 2; } |