/* * author: pavveu * task: Potyczki Algorytmiczne 2020 Runda 3 - Samochody Dostawcze [C] */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; #define FOR(iter, val) for(int iter = 0; iter < (val); iter++) #define all(x) begin(x), end(x) struct point { int type, x, y; point(int tt = 0, int xx=0, int yy=0) : type{tt}, x{xx}, y{yy} {} }; void go() { int n; cin >> n; vector<point> points(n); unordered_map<int,int> cnt[2]; vector<int> diffs; for (auto& p : points) { cin >> p.type >> p.x >> p.y; p.type--; p.y = -p.y; if ( p.type == 1 ) swap(p.x, p.y); cnt[p.type][p.x + p.y]++; diffs.push_back(p.x + p.y); } sort(all(diffs)); auto end_it = unique(all(diffs)); diffs.erase(end_it, diffs.end()); int ans { 0 }; for (int sum_coords : diffs) { ans += std::min(cnt[0][sum_coords], cnt[1][sum_coords]); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); go(); // test(); 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 | /* * author: pavveu * task: Potyczki Algorytmiczne 2020 Runda 3 - Samochody Dostawcze [C] */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; #define FOR(iter, val) for(int iter = 0; iter < (val); iter++) #define all(x) begin(x), end(x) struct point { int type, x, y; point(int tt = 0, int xx=0, int yy=0) : type{tt}, x{xx}, y{yy} {} }; void go() { int n; cin >> n; vector<point> points(n); unordered_map<int,int> cnt[2]; vector<int> diffs; for (auto& p : points) { cin >> p.type >> p.x >> p.y; p.type--; p.y = -p.y; if ( p.type == 1 ) swap(p.x, p.y); cnt[p.type][p.x + p.y]++; diffs.push_back(p.x + p.y); } sort(all(diffs)); auto end_it = unique(all(diffs)); diffs.erase(end_it, diffs.end()); int ans { 0 }; for (int sum_coords : diffs) { ans += std::min(cnt[0][sum_coords], cnt[1][sum_coords]); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); go(); // test(); return 0; } |