제출 #411317

#제출 시각아이디문제언어결과실행 시간메모리
411317hibye1217Detecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms332 KiB
#include "molecules.h"
#include <vector>
#include <algorithm>
#include <iostream>
using ll = long long;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    sort(w.begin(), w.end());
	std::vector<int> ans;
    int n = w.size();
    ll pre = 0, suf = 0;
    for (int i = 1; i <= n; i++){
		pre += w[i-1]; suf += w[n-i];
		if (pre > u){ return ans; }
		if (l <= pre && pre <= u){
			for (int j = 0; j < i; j++){ ans.push_back(j); }
			return ans;
		}
		if (l <= suf && suf <= u){
			for (int j = n-i; j < n; j++){ ans.push_back(j); }
			return ans;
		}
		if (pre < l && u < suf){
			ll sum = pre;
			for (int j = 0; ; j++){
				if (l <= sum && sum <= u){
					for (int k = j; k <= j+i; k++){ ans.push_back(k); }
					return ans;
				}
				sum -= w[j];
				sum += w[j+i];
			}
		}
    }
}

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...