# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
474768 | MohamedFaresNebili | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "molecules.h"
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using vl = vector<long long>;
#define mp make_pair
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin() , (x).end()
const int N = 2*100005;
const long long MOD = 1e9+7;
const long double EPS = 0.000000001;
const double PI = 3.14159265358979323846;
const int nx[4]={1, -1, 0, 0}, ny[4]={0, 0, 1, -1};
long long gcd(int a, int b) { return (b==0?a:gcd(b, a%b)); }
long long lcm(int a, int b) { return a*(b/gcd(a, b)); }
long long fact(int a) { return (a==1?1:a*fact(a-1)); }
int res=0, arr[2*100005];
void solve(int i, int l, int r, vector<int>w, int n, vector<int>a, int curr=0, int sum=0) {
if(i==n) {
if(sum>=l&&sum<=r) {
if(curr>res) {
for(int j=0;j<curr;j++) arr[j]=a[j];
}
res=max(res, curr);
}
return;
}
if(sum+w[i]>r) {
solve(i+1, l, r, w, n, a, curr, sum);
return;
}
a.pb(w[i]);
solve(i+1, l, r, w, n, a, curr+1, sum+w[i]);
a.pp();
solve(i+1, l, r, w, n, a, curr, sum);
}
vector<int> find_subset(int l, int u, vector<int>w, int n, vector<int> result) {
vector<int>ans; solve(0, l, u, w, n, ans);
for(int i=0;i<res;i++) result.pb(arr[i]);
return result;
}