Submission #679890

# Submission time Handle Problem Language Result Execution time Memory
679890 2023-01-09T15:20:21 Z peijar Ice Hockey World Championship (CEOI15_bobek) C++17
100 / 100
189 ms 16736 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
  out << "[";
  for (int i = 0; i < (int)vec.size(); ++i) {
    out << vec[i];
    if (i + 1 < (int)vec.size())
      out << ", ";
  }
  return out << "]";
}
} // namespace std

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << H;
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N, budget;
  cin >> N >> budget;
  vector<int> L, R;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    if (i % 2)
      R.push_back(x);
    else
      L.push_back(x);
  }

  int szL = L.size(), szR = R.size();
  vector<int> valL(1 << szL), valR(1 << szR);
  for (int msk = 0; msk < (1 << szL); ++msk) {
    for (int i = 0; i < szL; ++i)
      if ((1 << i) & msk) {
        valL[msk] = valL[msk ^ (1 << i)] + L[i];
        break;
      }
  }
  sort(valL.begin(), valL.end());
  for (int msk = 0; msk < (1 << szR); ++msk) {
    for (int i = 0; i < szR; ++i)
      if ((1 << i) & msk) {
        valR[msk] = valR[msk ^ (1 << i)] + R[i];
        break;
      }
  }
  dbg(L, R);
  sort(valR.rbegin(), valR.rend());
  dbg(valL);
  dbg(valR);
  int curL = 0;
  int sol = 0;
  for (int x : valR) {
    if (x > budget)
      continue;
    while (curL < (int)valL.size() and valL[curL] + x <= budget)
      ++curL;
    dbg(x, curL);
    sol += curL;
  }
  cout << sol << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1880 KB Output is correct
2 Correct 44 ms 4436 KB Output is correct
3 Correct 186 ms 16724 KB Output is correct
4 Correct 43 ms 4436 KB Output is correct
5 Correct 6 ms 1340 KB Output is correct
6 Correct 5 ms 828 KB Output is correct
7 Correct 9 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2388 KB Output is correct
2 Correct 15 ms 1876 KB Output is correct
3 Correct 64 ms 8532 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 10 ms 1368 KB Output is correct
7 Correct 9 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 3412 KB Output is correct
2 Correct 66 ms 6484 KB Output is correct
3 Correct 65 ms 6488 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 27 ms 6484 KB Output is correct
6 Correct 141 ms 16736 KB Output is correct
7 Correct 61 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 12628 KB Output is correct
2 Correct 15 ms 1860 KB Output is correct
3 Correct 5 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 4 ms 828 KB Output is correct
6 Correct 133 ms 12748 KB Output is correct
7 Correct 10 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1876 KB Output is correct
2 Correct 44 ms 4436 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 33 ms 6484 KB Output is correct
6 Correct 14 ms 1876 KB Output is correct
7 Correct 178 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 16736 KB Output is correct
2 Correct 16 ms 1880 KB Output is correct
3 Correct 5 ms 848 KB Output is correct
4 Correct 189 ms 16724 KB Output is correct
5 Correct 40 ms 8532 KB Output is correct
6 Correct 9 ms 1372 KB Output is correct
7 Correct 22 ms 2388 KB Output is correct