답안 #321792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321792 2020-11-13T11:42:14 Z nikatamliani Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
int find_subset(int l, int u, int w[], int n, int result[]) {
    vector<int> indices(n);
    for(int i = 0; i < n; ++i) {
        indices[i] = i; 
    }
    sort(indices.begin(), indices.end(), [&](int x, int y) {
        return w[x] > w[y];
    });
    #define ll long long
    ll sum = 0, cnt = 0, save = 0;
    for(int i = 0; i < n; ++i) {
        int index = indices[i]; 
        sum += w[index];
        result[cnt++] = index; 
        if(sum >= l) {
            save = i + 1;
            break;
        }
    }
    int ptr = 0; 
    while(save < n && sum > u) {
        sum -= result[ptr];
        result[ptr++] = indices[save++];
        sum += result[ptr];
    }
    if(sum <= u) {
        assert(sum >= l);
        return 1;
    }
    memset(result, 0, sizeof result);
    return 0;
}
// int main() {
//     int l, u, n;
//     cin >> l >> u >> n;
//     int w[n], result[n];
//     for(int i = 0; i < n; ++i) {
//         cin >> w[i];
//     }
//     cout << find_subset(l, u, w, n, result) << '\n';
//     for(int i = 0; i < n; ++i) {
//         cout << result[i] << ' ';
//     }
// }

Compilation message

molecules.cpp: In function 'int find_subset(int, int, int*, int, int*)':
molecules.cpp:33:30: warning: 'sizeof' on array function parameter 'result' will return size of 'int*' [-Wsizeof-array-argument]
   33 |     memset(result, 0, sizeof result);
      |                              ^~~~~~
molecules.cpp:4:51: note: declared here
    4 | int find_subset(int l, int u, int w[], int n, int result[]) {
      |                                               ~~~~^~~~~~~~
molecules.cpp:33:23: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
   33 |     memset(result, 0, sizeof result);
      |                       ^~~~~~~~~~~~~
/tmp/cc8EhYwn.o: In function `main':
grader.cpp:(.text.startup+0x139): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status