Submission #390933

#TimeUsernameProblemLanguageResultExecution timeMemory
390933usachevd0Teams (IOI15_teams)C++17
21 / 100
4094 ms16324 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
  return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
  return y > x ? (x = y, true) : false;
}
void debug_out() {
  cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
  cerr << ' ' << A;
  debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
  for (int i = 0; i < n; ++i) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
#ifdef DEBUG
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
  #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
  #define debug(...) 1337
  #define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) {
  for (auto& x : v) {
    stream << x << ' ';
  }
  return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
  return stream << p.first << ' ' << p.second;
}

const int inf32 = 1e9;
const int maxN = 5e5 + 5;
const int sqrtN = 710;
const int maxQ = 2e5 + 5;
const int maxS = maxQ;

int n;
int L[maxN], R[maxN];

void init(int _n, int* _L, int* _R) {
  n = _n;
  for (int i = 0; i < n; ++i) {
    L[i] = _L[i];
    R[i] = _R[i];
  }
}

int count_stu(int x1, int x2) {
  if (x1 >= x2) {
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += x1 < L[i] && L[i] <= x2 && x2 <= R[i];
  }
  return ans;
}

int bx[maxS], bc[maxN];
int dp[maxN];
bool can(int k, int* a) {
  sort(a, a + k);
  if (accumulate(a, a + k, 0) > n) {
    return false;
  }
  int nk = 0;
  for (int i = 0; i < k; ++i) {
    if (nk > 0 && bx[nk - 1] == a[i]) {
      ++bc[nk - 1];
    } else {
      bx[nk] = a[i];
      bc[nk] = 1;
      ++nk;
    }
  }
  k = nk;
  assert(k <= sqrtN);
  fill(dp, dp + k + 1, inf32);
  dp[0] = 0;
  for (int i = 0; i < k; ++i) {
    dp[i + 1] = count_stu(-1, bx[i]) - bx[i] * bc[i];
    for (int j = 0; j < i; ++j) {
      chkmin(dp[i + 1], dp[j + 1] + count_stu(bx[j], bx[i]) - bx[i] * bc[i]);
    }
  }
//  mdebug(dp, k + 1);
  return *min_element(dp, dp + k + 1) >= 0;
}

#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
  freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  int* L = new int[n];
  int* R = new int[n];
  for (int i = 0; i < n; ++i) {
    cin >> L[i] >> R[i];
  }
  init(n, L, R);
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int k;
    cin >> k;
    int* a = new int[k];
    for (int j = 0; j < k; ++j) {
      cin >> a[j];
    }
    cout << can(k, a) << '\n';
  }

  return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...