이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define F first
#define S second
#define pb push_back
#define sz(x) (ll)x.size()
typedef vector <ll> vi;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
#define N 100
#define MAX_SUM 100000
ll dp[N+1][MAX_SUM+1];
vi w;
vi ans;
ll l, r;
bool foundAns = false;
void tabb(ll n) {
for (ll i =0; i<n; i++) cout<<"\t";
}
bool solve(ll n, ll s, ll tab = 0){
// tabb(tab);
// dbg2(n,s);
if (foundAns){
// dbg(1);
return false;
}
if (n >= sz(w)){
// dbg(2);
bool foundAns = (l <= s && s <= r);
// dbg3(n,s,foundAns)
return foundAns;
}
if (s > r)return false;
if (dp[n][s] != -1) return dp[n][s];
bool ans1 = solve(n+1, s+w[n], tab+1);
if (ans1){
ans.pb(n);
return dp[n][s] = ans1;
}
bool ans2 = solve(n+1, s, tab+1);
return dp[n][s] = (ans1 || ans2);
}
vi find_subset(int L, int R, vi c) {
w = c;
l = L, r = R;
for (ll i =0; i<=N; i++){
for (ll j = 0; j<=MAX_SUM; j++){
dp[i][j] = -1;
}
}
solve(0, 0);
return ans;
}
/*
4 15 17
6 8 8 7
*/
컴파일 시 표준 에러 (stderr) 메시지
molecules.cpp: In function 'bool solve(int, int, int)':
molecules.cpp:58:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
58 | return dp[n][s] = ans1;
| ~~~~~~~~~^~~~~~
molecules.cpp:63:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
63 | return dp[n][s] = (ans1 || ans2);
| ~~~~~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |