제출 #242407

#제출 시각아이디문제언어결과실행 시간메모리
242407joseacaz친구 (IOI14_friend)C++17
27 / 100
47 ms65540 KiB
#include "friend.h" #include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1005; int prot[3], on[MAXN], DP[MAXN][2], vis[MAXN][2]; int aux, ans, c[MAXN]; vi Graph[MAXN]; int solve(int node, int f) { if(vis[node][f]) return DP[node][f]; int res1 = 0, res2 = 0; for(auto i : Graph[node]) { res1 += solve(node, 1); res2 += solve(node, 0); } vis[node][f] = 1; if(f) return DP[node][f] = max(res1, res2 + c[node]); else return DP[node][f] = res1; } // Find out best sample int findSample(int N, int _conf[], int host[], int protocol[]) { if(N > 1000) return 0; for(int i = 0; i < N; i++) { c[i] = _conf[i]; if(i >= 1) prot[protocol[i]]++; } //S1 if(N <= 10) { for(int i = 1; i < N; i++) { if(protocol[i] == 0) { Graph[host[i]].pb(i); Graph[i].pb(host[i]); } else if(protocol[i] == 1) { for(auto v : Graph[host[i]]) { Graph[v].pb(i); Graph[i].pb(v); } } else if(protocol[i] == 2) { for(auto v : Graph[host[i]]) { Graph[v].pb(i); Graph[i].pb(v); } Graph[host[i]].pb(i); Graph[i].pb(host[i]); } } for(int i = 0; i < (1 << N); i++) { aux = 0; for(int j = 0; j < N; j++) { on[j] = 0; if(i & (1 << j)) { on[j] = 1; aux += c[j]; } } bool ind = 1; for(int node = 0; node < N; node++) if(on[node]) for(auto j : Graph[node]) if(on[j]) ind = 0; if(!ind) continue; ans = max(ans, aux); } } //S2 else if(prot[1] == N - 1) { for(int i = 0; i < N; i++) ans += c[i]; } //S3 else if(prot[2] == N - 1) { for(int i = 0; i < N; i++) ans = max(ans, c[i]); } //S4 else if(prot[0] == N - 1) { for(int i = 1; i < N; i++) { if(protocol[i] == 0) { Graph[host[i]].pb(i); Graph[i].pb(host[i]); } } ans = solve(0, 1); } return ans; }

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

friend.cpp: In function 'int solve(int, int)':
friend.cpp:24:14: warning: unused variable 'i' [-Wunused-variable]
     for(auto i : Graph[node])
              ^
#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...