#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
const int X = 1;
const int Y = 2;
struct Polozenie {
Polozenie(int type, int val) : type(type), val(val) {}
bool operator<(const Polozenie &o) const {
return std::tie(type, val) < std::tie(o.type, o.val);
}
int type;
int val;
};
struct komparator {
bool operator()(const std::pair<std::set<int> *, int> &a,
const std::pair<std::set<int> *, int> &b) const {
if (a.first->size() < b.first->size()) {
return true;
}
if (a.first->size() == b.first->size()) {
return a.second < b.second;
}
return false;
}
};
int main() {
int N = 0;
std::cin >> N;
int maxX = 0;
int maxY = 0;
std::map<int, std::set<int>> graf;
std::map<Polozenie, std::set<int>> dostawcyPerPolozenie;
for (int i = 0; i < N; ++i) {
int type = 0, polozenie = 0, time = 0;
std::cin >> type;
std::cin >> polozenie;
std::cin >> time;
dostawcyPerPolozenie[{type, polozenie}].insert(time);
type == X ? maxX = std::max(maxX, polozenie)
: maxY = std::max(maxY, polozenie);
}
// DEBUG
// fprintf(stderr, "maxX: %d, maxY: %d\n", maxX, maxY);
//
std::set<int> set1;
std::set<int> set2;
for (int i = 1; i <= maxX; ++i) {
if (dostawcyPerPolozenie.find({X, i}) == dostawcyPerPolozenie.end()) {
continue;
}
for (int j = 1; j <= maxY; ++j) {
if (dostawcyPerPolozenie.find({Y, j}) == dostawcyPerPolozenie.end()) {
continue;
}
std::map<int, int> czasy_kolizji; // czas kolizji -> dostawca
for (auto &d : dostawcyPerPolozenie[{X, i}]) {
czasy_kolizji.insert({j + d, d});
}
for (auto &d : dostawcyPerPolozenie[{Y, j}]) {
auto iter = czasy_kolizji.find(i + d);
if (iter != czasy_kolizji.end()) {
int d1 = d;
int d2 = iter->second;
set1.insert(d1);
set2.insert(d2);
}
}
}
}
std::cout << std::min(set1.size(), set2.size());
return 0;
}
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <functional> #include <iostream> #include <map> #include <set> #include <tuple> const int X = 1; const int Y = 2; struct Polozenie { Polozenie(int type, int val) : type(type), val(val) {} bool operator<(const Polozenie &o) const { return std::tie(type, val) < std::tie(o.type, o.val); } int type; int val; }; struct komparator { bool operator()(const std::pair<std::set<int> *, int> &a, const std::pair<std::set<int> *, int> &b) const { if (a.first->size() < b.first->size()) { return true; } if (a.first->size() == b.first->size()) { return a.second < b.second; } return false; } }; int main() { int N = 0; std::cin >> N; int maxX = 0; int maxY = 0; std::map<int, std::set<int>> graf; std::map<Polozenie, std::set<int>> dostawcyPerPolozenie; for (int i = 0; i < N; ++i) { int type = 0, polozenie = 0, time = 0; std::cin >> type; std::cin >> polozenie; std::cin >> time; dostawcyPerPolozenie[{type, polozenie}].insert(time); type == X ? maxX = std::max(maxX, polozenie) : maxY = std::max(maxY, polozenie); } // DEBUG // fprintf(stderr, "maxX: %d, maxY: %d\n", maxX, maxY); // std::set<int> set1; std::set<int> set2; for (int i = 1; i <= maxX; ++i) { if (dostawcyPerPolozenie.find({X, i}) == dostawcyPerPolozenie.end()) { continue; } for (int j = 1; j <= maxY; ++j) { if (dostawcyPerPolozenie.find({Y, j}) == dostawcyPerPolozenie.end()) { continue; } std::map<int, int> czasy_kolizji; // czas kolizji -> dostawca for (auto &d : dostawcyPerPolozenie[{X, i}]) { czasy_kolizji.insert({j + d, d}); } for (auto &d : dostawcyPerPolozenie[{Y, j}]) { auto iter = czasy_kolizji.find(i + d); if (iter != czasy_kolizji.end()) { int d1 = d; int d2 = iter->second; set1.insert(d1); set2.insert(d2); } } } } std::cout << std::min(set1.size(), set2.size()); return 0; } |
English