Submission #1099652

# Submission time Handle Problem Language Result Execution time Memory
1099652 2024-10-12T00:40:07 Z Trn115 Detecting Molecules (IOI16_molecules) C++17
Compilation error
0 ms 0 KB
#include "molecules.h"
#include <bits/stdc++.h>

#define int long long
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define dbg(v) cerr << "\n" << #v << " = " << v << "\n"

using namespace std;

vector<int> find_subset(int l, int u, vector<int> w) {
    int n = w.size();
    vector<pair<int,int>> a;
    for (int i = 0; i < n; ++i) a.push_back({w[i], i});
    sort(all(a));
    
    int le = 0, sum = 0;
    vector<int> res;
    for (int i = 0; i < n; ++i) {
        sum += a[i].fi;
        while (i-le+1 > 1 && sum > u) sum -= a[le++].fi;
        if (l <= sum && sum <= u) {
            for (int j = le; j <= i; ++j) res.push_back(a[j].se);
            break;
        }
    }
    return res;
}

int main() {
    int n, l, u;
    assert(3 == scanf("%d %d %d", &n, &l, &u));
    std::vector<int> w(n);
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &w[i]));
    std::vector<int> result = find_subset(l, u, w);
    
    
    printf("%d\n", (int)result.size());
    for (int i = 0; i < (int)result.size(); i++)
        printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}

Compilation message

cc1plus: error: '::main' must return 'int'
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from molecules.cpp:2:
molecules.cpp: In function 'int main()':
molecules.cpp:33:23: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   33 |     assert(3 == scanf("%d %d %d", &n, &l, &u));
      |                       ^~~~~~~~~~  ~~
      |                                   |
      |                                   long long int*
molecules.cpp:33:25: note: format string is defined here
   33 |     assert(3 == scanf("%d %d %d", &n, &l, &u));
      |                        ~^
      |                         |
      |                         int*
      |                        %lld
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from molecules.cpp:2:
molecules.cpp:33:23: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   33 |     assert(3 == scanf("%d %d %d", &n, &l, &u));
      |                       ^~~~~~~~~~      ~~
      |                                       |
      |                                       long long int*
molecules.cpp:33:28: note: format string is defined here
   33 |     assert(3 == scanf("%d %d %d", &n, &l, &u));
      |                           ~^
      |                            |
      |                            int*
      |                           %lld
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from molecules.cpp:2:
molecules.cpp:33:23: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
   33 |     assert(3 == scanf("%d %d %d", &n, &l, &u));
      |                       ^~~~~~~~~~          ~~
      |                                           |
      |                                           long long int*
molecules.cpp:33:31: note: format string is defined here
   33 |     assert(3 == scanf("%d %d %d", &n, &l, &u));
      |                              ~^
      |                               |
      |                               int*
      |                              %lld
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from molecules.cpp:2:
molecules.cpp:36:27: warning: format '%d' expects argument of type 'int*', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type*' {aka 'long long int*'} [-Wformat=]
   36 |         assert(1 == scanf("%d", &w[i]));
      |                           ^~~~
molecules.cpp:36:29: note: format string is defined here
   36 |         assert(1 == scanf("%d", &w[i]));
      |                            ~^
      |                             |
      |                             int*
      |                            %lld
molecules.cpp:40:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   40 |     printf("%d\n", (int)result.size());
      |             ~^     ~~~~~~~~~~~~~~~~~~
      |              |     |
      |              int   long long int
      |             %lld
molecules.cpp:42:18: warning: format '%d' expects argument of type 'int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} [-Wformat=]
   42 |         printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
      |                 ~^
      |                  |
      |                  int
      |                 %lld