Submission #1141329

#TimeUsernameProblemLanguageResultExecution timeMemory
1141329harry_tm_18Detecting Molecules (IOI16_molecules)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define long long ll
const int N = 1e5;
vector<int> adj[N];
vector<bool> c(N);

bool check(int l, int u, int max, int min){
    return u - l >= max - min;
}

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[i].push_back({w[i] i});
    }
    sort(a.begin(), a.end());

    vector<int> suffix(n), ans;
    suffix[n-1] = a[n-1];

    for(int i=n-2; i>=0; --i){
        suffix[i] = suffix[i+1] + a[i];
    } 

    int prefixSum = 0;

    for(int i=0; i<n; ++i){
        if(prefixSum > u) break;
        if(prefixSum <= l){
            for(int j=0; j<=i; ++i){
                ans.push_back([i].second);
            }
            return ans;
        }

        int v = 0, g = n-1;

        while(v <= g){
            int mid = a[v].first + (a[g].first - a[v].first) / 2;

            if(prefixSum + suffix[mid] >= l && prefixSum + suffix[mid] <= u){
                for(int j=0; j<i; ++j){
                    ans.push_back(a[j].second);
                }
                for(int j=mid+1; j<n; ++j){
                    ans.push_back(a[j].second);
                }
                return ans;
            } else if(prefixSum + suffix[mid] > u){
                mid = mid + 1;
            } else {
                mid = mid - 1;
            }
        }
        prefix += a[i].first;
    }

    return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:19:14: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'push_back'
   19 |         a[i].push_back({w[i] i});
      |              ^~~~~~~~~
molecules.cpp:19:30: error: expected '}' before 'i'
   19 |         a[i].push_back({w[i] i});
      |                        ~     ^
molecules.cpp:19:29: error: expected ')' before 'i'
   19 |         a[i].push_back({w[i] i});
      |                       ~     ^~
      |                             )
molecules.cpp:19:32: error: expected primary-expression before ')' token
   19 |         a[i].push_back({w[i] i});
      |                                ^
molecules.cpp:20:5: warning: no return statement in function returning non-void [-Wreturn-type]
   20 |     }
      |     ^
molecules.cpp: At global scope:
molecules.cpp:21:9: error: expected constructor, destructor, or type conversion before '(' token
   21 |     sort(a.begin(), a.end());
      |         ^
molecules.cpp:23:24: error: 'n' was not declared in this scope
   23 |     vector<int> suffix(n), ans;
      |                        ^
molecules.cpp:24:5: error: 'suffix' does not name a type
   24 |     suffix[n-1] = a[n-1];
      |     ^~~~~~
molecules.cpp:26:5: error: expected unqualified-id before 'for'
   26 |     for(int i=n-2; i>=0; --i){
      |     ^~~
molecules.cpp:26:20: error: 'i' does not name a type
   26 |     for(int i=n-2; i>=0; --i){
      |                    ^
molecules.cpp:26:26: error: expected unqualified-id before '--' token
   26 |     for(int i=n-2; i>=0; --i){
      |                          ^~
molecules.cpp:32:5: error: expected unqualified-id before 'for'
   32 |     for(int i=0; i<n; ++i){
      |     ^~~
molecules.cpp:32:20: error: 'n' was not declared in this scope
   32 |     for(int i=0; i<n; ++i){
      |                    ^
molecules.cpp:32:20: error: 'n' was not declared in this scope
molecules.cpp:32:20: error: 'n' was not declared in this scope
molecules.cpp:32:20: error: 'n' was not declared in this scope
molecules.cpp:32:20: error: 'n' was not declared in this scope
molecules.cpp:32:20: error: 'n' was not declared in this scope
molecules.cpp:32:20: error: 'n' was not declared in this scope
molecules.cpp:32:20: error: 'n' was not declared in this scope
molecules.cpp:32:20: error: 'n' was not declared in this scope
molecules.cpp:32:18: error: 'i' does not name a type
   32 |     for(int i=0; i<n; ++i){
      |                  ^
molecules.cpp:32:23: error: expected unqualified-id before '++' token
   32 |     for(int i=0; i<n; ++i){
      |                       ^~
molecules.cpp:63:5: error: expected unqualified-id before 'return'
   63 |     return ans;
      |     ^~~~~~
molecules.cpp:64:1: error: expected declaration before '}' token
   64 | }
      | ^
molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~