답안 #231010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231010 2020-05-12T10:31:26 Z AlexLuchianov Ice Hockey World Championship (CEOI15_bobek) C++14
100 / 100
665 ms 8684 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) ? (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 40;

int lowerthan(vector<ll> &samples, ll target){
  int x = 0;
  for(int jump = (1 << 20); 0 < jump; jump /= 2){
    if(x + jump < samples.size() && samples[x + jump] <= target)
      x += jump;
  }
  if(samples[x] <= target)
    return x + 1;
  else
    return x;
}

void _generate(vector<ll> v, vector<ll> &result){
  int n = v.size();
  for(int mask = 0; mask < (1 << n); mask++){
    ll sum = 0;
    for(int i = 0; i < n; i++)
      if(0 < ((1 << i) & mask))
        sum += v[i];
    result.push_back(sum);
  }
}

ll _count(vector<ll> v, vector<ll> &samples, ll target){
  int n = v.size();
  ll result = 0;
  for(int mask = 0; mask < (1 << n); mask++){
    ll sum = 0;
    for(int i = 0; i < n; i++)
      if(0 < ((1 << i) & mask))
        sum += v[i];
    result += lowerthan(samples, target - sum);
  }
  return result;
}

int main()
{
  int n;
  ll lim;
  cin >> n >> lim;
  vector<ll> v1, v2;
  for(int i = 1;i <= n; i++){
    ll val;
    cin >> val;
    if(i <= n / 2)
      v1.push_back(val);
    else
      v2.push_back(val);
  }
  vector<ll> samples;
  _generate(v1, samples);
  sort(samples.begin(), samples.end());
  cout << _count(v2, samples, lim);
  return 0;
}

Compilation message

bobek.cpp: In function 'int lowerthan(std::vector<long long int>&, ll)':
bobek.cpp:18:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(x + jump < samples.size() && samples[x + jump] <= target)
        ~~~~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1020 KB Output is correct
2 Correct 97 ms 2548 KB Output is correct
3 Correct 665 ms 8672 KB Output is correct
4 Correct 99 ms 2548 KB Output is correct
5 Correct 20 ms 1020 KB Output is correct
6 Correct 12 ms 768 KB Output is correct
7 Correct 20 ms 1020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 1528 KB Output is correct
2 Correct 30 ms 1020 KB Output is correct
3 Correct 190 ms 4592 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 11 ms 768 KB Output is correct
6 Correct 20 ms 1020 KB Output is correct
7 Correct 20 ms 1020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 1528 KB Output is correct
2 Correct 152 ms 2548 KB Output is correct
3 Correct 152 ms 2548 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 108 ms 2548 KB Output is correct
6 Correct 319 ms 8676 KB Output is correct
7 Correct 120 ms 2548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 4584 KB Output is correct
2 Correct 28 ms 1020 KB Output is correct
3 Correct 13 ms 768 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 11 ms 768 KB Output is correct
6 Correct 243 ms 4592 KB Output is correct
7 Correct 20 ms 1020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1020 KB Output is correct
2 Correct 96 ms 2560 KB Output is correct
3 Correct 12 ms 768 KB Output is correct
4 Correct 12 ms 768 KB Output is correct
5 Correct 118 ms 2548 KB Output is correct
6 Correct 27 ms 1020 KB Output is correct
7 Correct 334 ms 8672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 399 ms 8672 KB Output is correct
2 Correct 30 ms 1020 KB Output is correct
3 Correct 12 ms 768 KB Output is correct
4 Correct 609 ms 8684 KB Output is correct
5 Correct 157 ms 4596 KB Output is correct
6 Correct 20 ms 1020 KB Output is correct
7 Correct 41 ms 1528 KB Output is correct