Submission #1198349

#TimeUsernameProblemLanguageResultExecution timeMemory
1198349grafffDetecting Molecules (IOI16_molecules)C++20
Compilation error
0 ms0 KiB
#include "molecules.h"

#include <algorithm>

using namespace std;

vector <int> solve(int l, int u, vector <int> w){
    int n = w.size(), res = 0;
    map <int, int> mp;
    set <int> st = {0};
    mp[0] = -1;
    bool flag = false;
    for(int i = 0; i < n; i++){
        for(int j : st){
            int x = j + w[i];
            if(mp[x] == 0 && w[0] != x){
                mp[x] = i;
            }
            if(l <= x && x <= u){
                flag = true;
                res = x;
                break;
            }
        }
        if(flag){
            break;
        }
        st = {};
        for(auto &[x, y] : mp){
            st.insert(x);
        }
    }
    vector <int> ans;
    int x = mp[res];
    while(x >= 0){
        ans.push_back(x);
        res -= w[x];
        x = mp[res];
    }
    return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> solve(int, int, std::vector<int>)':
molecules.cpp:9:5: error: 'map' was not declared in this scope
    9 |     map <int, int> mp;
      |     ^~~
molecules.cpp:4:1: note: 'std::map' is defined in header '<map>'; did you forget to '#include <map>'?
    3 | #include <algorithm>
  +++ |+#include <map>
    4 | 
molecules.cpp:9:10: error: expected primary-expression before 'int'
    9 |     map <int, int> mp;
      |          ^~~
molecules.cpp:10:5: error: 'set' was not declared in this scope
   10 |     set <int> st = {0};
      |     ^~~
molecules.cpp:4:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'?
    3 | #include <algorithm>
  +++ |+#include <set>
    4 | 
molecules.cpp:10:10: error: expected primary-expression before 'int'
   10 |     set <int> st = {0};
      |          ^~~
molecules.cpp:11:5: error: 'mp' was not declared in this scope
   11 |     mp[0] = -1;
      |     ^~
molecules.cpp:14:21: error: 'st' was not declared in this scope; did you mean 'std'?
   14 |         for(int j : st){
      |                     ^~
      |                     std
molecules.cpp:28:9: error: 'st' was not declared in this scope; did you mean 'std'?
   28 |         st = {};
      |         ^~
      |         std
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
      |         ^~~~