Submission #654817

#TimeUsernameProblemLanguageResultExecution timeMemory
654817sandry24Detecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define pb push_back #define mp make_pair #define f first #define s second vi find_subset(int l, int u, vi w){ vector<pi> a; for(int i = 0; i < w.size(); i++) a.pb(mp(w[i], i+1)); sort(a.begin(), a.end()); int sum = 0, left = 0, right = 0; for(int i = 0; i < w.size(); i++){ if(sum + a[i].f <= u){ sum += a[i].f; right = i; } else break; } while(sum < l && right != w.size()-1){ sum -= a[left].f; sum += a[right+1].f; right++; left++; if(sum > u) return {}; } if(sum < l) return {}; vi ans; for(int i = left; i <= right; i++) ans.pb(a[i].s); return ans; } void solve(){ vi w = {15, 17, 16, 18}; vi ans = find_subset(10, 20, w); for(auto i : ans) cout << i << ' '; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

molecules.cpp: In function 'vi find_subset(int, int, vi)':
molecules.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0; i < w.size(); i++)
      |                    ~~^~~~~~~~~~
molecules.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i = 0; i < w.size(); i++){
      |                    ~~^~~~~~~~~~
molecules.cpp:25:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     while(sum < l && right != w.size()-1){
      |                      ~~~~~~^~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc1YGQkz.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwMr5xA.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status