Cod sursa(job #2629901)

Utilizator segtreapMihnea Andreescu segtreap Data 23 iunie 2020 11:01:28
Problema Regiuni Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

const int N = 1000 + 7;
int m, n, a[N], b[N], c[N], x[N], y[N], cnt = 1;
vector<int> who[N];

bool f(int i, int j) {
  return (a[i] * (long long) x[j] + b[i] * (long long) y[j] + c[i] > 0);
}

int main() {
  freopen ("regiuni.in", "r", stdin);
  freopen ("regiuni.out", "w", stdout);
  scanf("%d %d", &m, &n);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x[i], &y[i]);
    who[1].push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    int cnt2 = cnt;
    for (int it = 1; it <= cnt; it++) {
      vector<int> a, b;
      for (auto &j : who[it]) {
        if (f(i, j)) {
          a.push_back(j);
        } else {
          b.push_back(j);
        }
      }
      if (a.empty() || b.empty()) {
        continue;
      }
      who[it] = a;
      who[++cnt2] = b;
    }
    cnt = cnt2;
  }
  printf("%d\n", cnt);
  return 0;
}