답안 #23126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
23126 2017-05-03T10:43:09 Z model_code Ice Hockey World Championship (CEOI15_bobek) C++14
100 / 100
373 ms 17500 KB
/* Written by Filip Hlasek 2015 */
#include <cstdio>
#include <algorithm>
using namespace std;

#define MAXN 40
long long A[MAXN];

#define MAX (1 << ((MAXN + 1) / 2))
long long sums1[MAX], sums2[MAX];

void gen_subset_sums(long long A[], int N, long long sums[]) {
  for (int mask = 0; mask < (1 << N); ++mask) {
    long long sum = 0;
    for (int i = 0; i < N; ++i) if (mask & (1 << i)) sum += A[i];
    sums[mask] = sum;
  }
  sort(sums, sums + (1 << N));
}

int main(int argc, char *argv[]) {
  int N;
  long long M;
  scanf("%d%lld", &N, &M);
  for (int i = 0; i < N; ++i) scanf("%lld", A + i);

  int N1 = N / 2, N2 = N - N1;
  gen_subset_sums(A, N1, sums1);
  gen_subset_sums(A + N1, N2, sums2);

  long long ans = 0;
  int pos2 = (1 << N2);
  for (int pos1 = 0; pos1 < (1 << N1); ++pos1) {
    while (pos2 && sums1[pos1] + sums2[pos2 - 1] > M) pos2--;
    ans += pos2;
  }

  printf("%lld\n", ans);

  return 0;
}

Compilation message

bobek.cpp: In function 'int main(int, char**)':
bobek.cpp:24:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld", &N, &M);
                          ^
bobek.cpp:25:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 0; i < N; ++i) scanf("%lld", A + i);
                                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17500 KB Output is correct
2 Correct 0 ms 17500 KB Output is correct
3 Correct 0 ms 17500 KB Output is correct
4 Correct 0 ms 17500 KB Output is correct
5 Correct 0 ms 17500 KB Output is correct
6 Correct 0 ms 17500 KB Output is correct
7 Correct 0 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17500 KB Output is correct
2 Correct 0 ms 17500 KB Output is correct
3 Correct 0 ms 17500 KB Output is correct
4 Correct 0 ms 17500 KB Output is correct
5 Correct 0 ms 17500 KB Output is correct
6 Correct 0 ms 17500 KB Output is correct
7 Correct 0 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17500 KB Output is correct
2 Correct 0 ms 17500 KB Output is correct
3 Correct 0 ms 17500 KB Output is correct
4 Correct 0 ms 17500 KB Output is correct
5 Correct 0 ms 17500 KB Output is correct
6 Correct 0 ms 17500 KB Output is correct
7 Correct 0 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 17500 KB Output is correct
2 Correct 83 ms 17500 KB Output is correct
3 Correct 356 ms 17500 KB Output is correct
4 Correct 83 ms 17500 KB Output is correct
5 Correct 13 ms 17500 KB Output is correct
6 Correct 6 ms 17500 KB Output is correct
7 Correct 16 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 17500 KB Output is correct
2 Correct 29 ms 17500 KB Output is correct
3 Correct 146 ms 17500 KB Output is correct
4 Correct 0 ms 17500 KB Output is correct
5 Correct 6 ms 17500 KB Output is correct
6 Correct 16 ms 17500 KB Output is correct
7 Correct 16 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 17500 KB Output is correct
2 Correct 133 ms 17500 KB Output is correct
3 Correct 123 ms 17500 KB Output is correct
4 Correct 0 ms 17500 KB Output is correct
5 Correct 89 ms 17500 KB Output is correct
6 Correct 309 ms 17500 KB Output is correct
7 Correct 123 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 17500 KB Output is correct
2 Correct 26 ms 17500 KB Output is correct
3 Correct 6 ms 17500 KB Output is correct
4 Correct 0 ms 17500 KB Output is correct
5 Correct 6 ms 17500 KB Output is correct
6 Correct 263 ms 17500 KB Output is correct
7 Correct 16 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 17500 KB Output is correct
2 Correct 83 ms 17500 KB Output is correct
3 Correct 6 ms 17500 KB Output is correct
4 Correct 6 ms 17500 KB Output is correct
5 Correct 89 ms 17500 KB Output is correct
6 Correct 26 ms 17500 KB Output is correct
7 Correct 339 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 353 ms 17500 KB Output is correct
2 Correct 29 ms 17500 KB Output is correct
3 Correct 6 ms 17500 KB Output is correct
4 Correct 373 ms 17500 KB Output is correct
5 Correct 116 ms 17500 KB Output is correct
6 Correct 16 ms 17500 KB Output is correct
7 Correct 39 ms 17500 KB Output is correct