답안 #469261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469261 2021-08-31T09:34:35 Z cpp219 Džumbus (COCI19_dzumbus) C++14
0 / 110
1000 ms 460 KB
#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
*/

Compilation message

dzumbus.cpp: In function 'int main()':
dzumbus.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
dzumbus.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(task".ans","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -