Submission #446037

#TimeUsernameProblemLanguageResultExecution timeMemory
446037prvocisloDominance (CEOI08_dominance)C++17
100 / 100
18 ms512 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; struct obdl { int r1, c1, r2, c2; }; const ll inf = 1e10; ll count(ll r1, ll c1, ll r2, ll c2) // spocita pocet platnych bodov, vratane { r1 += inf, c1 += inf, r2 += inf, c2 += inf; ll even_rows = r2/2 - (r1-1)/2, odd_rows = r2 - r1 + 1 - even_rows; ll even_columns = c2/2 - (c1-1)/2, odd_columns = c2 - c1 + 1 - even_columns; return even_rows * even_columns + odd_rows * odd_columns; } struct udalost { ll x, y1, y2; int d; }; bool cmp(const udalost &a, const udalost &b) { return a.x < b.x; } int main() { ios::sync_with_stdio(false); cin.tie(0); int w, h, n; cin >> w >> h >> n; vector<udalost> e; set<int> sy; for (int i = 0, x, y, d; i < n; i++) { char c; cin >> c >> x >> y >> d; int delta = c == 'W' ? 1 : -1; e.push_back({x-y-d, x+y-d, x+y+d+1, delta}); e.push_back({x-y+d+1, x+y-d, x+y+d+1, -delta}); } for (udalost i : e) sy.insert(i.y1), sy.insert(i.y2); vector<int> vy(sy.begin(), sy.end()), sum(vy.size(), 0); sort(e.begin(), e.end(), cmp); ll cntw = 0, cntb = 0; //for (int j = 0; j < vy.size(); j++) cout << vy[j] << " "; //cout << endl << "============" << endl; for (int i = 0; i < e.size()-1; i++) { for (int j = 0; j < vy.size(); j++) if (e[i].y1 <= vy[j] && vy[j] < e[i].y2) sum[j] += e[i].d; for (int j = 0; j < vy.size() - 1; j++) { ll ok = count(e[i].x, vy[j], e[i+1].x-1, vy[j+1]-1); if (sum[j] > 0) cntw += ok; if (sum[j] < 0) cntb += ok; } //for (int j = 0; j < vy.size(); j++) cout << sum[j] << " "; //cout << "| " << e[i].x << endl; } cout << cntw << " " << cntb << "\n"; return 0; }

Compilation message (stderr)

dominance.cpp: In function 'int main()':
dominance.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<udalost>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = 0; i < e.size()-1; i++)
      |                     ~~^~~~~~~~~~~~
dominance.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int j = 0; j < vy.size(); j++) if (e[i].y1 <= vy[j] && vy[j] < e[i].y2)
      |                         ~~^~~~~~~~~~~
dominance.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int j = 0; j < vy.size() - 1; j++)
      |                         ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...