# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
469261 | cpp219 | Džumbus (COCI19_dzumbus) | C++14 | 1090 ms | 460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e3 + 9;
const ll inf = 1e9 + 7;
vector<ll> g[N],dp[2][N],mix[N];
ll n,m,Q,a[N],total,was[N],ans[N],b[N],kq;
LL q[200002];
ll cal(){
ll now = 0,have = 0;
for (ll i = 1;i <= n;i++){
if (!b[i]) continue;
now += a[i];
for (auto node : g[i]){
if (b[node]){
have++; break;
}
}
}
if (now <= total) return have;
return 0;
}
void f(ll i){
if (i > n){
kq = max(kq,cal());
return;
}
b[i] = 1; f(i + 1);
b[i] = 0; f(i + 1);
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".ans","w",stdout);
}
cin>>n>>m;
for (ll i = 1;i <= n;i++) cin>>a[i];
while(m--){
ll x,y; cin>>x>>y;
g[x].push_back(y); g[y].push_back(x);
}
cin>>Q;
while(Q--){
cin>>total; kq = 0; f(1);
cout<<kq<<"\n";
}
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |