제출 #874107

#제출 시각아이디문제언어결과실행 시간메모리
874107dzuizz친구 (IOI14_friend)C++14
46 / 100
39 ms10804 KiB
// Subtask 4 #include <bits/stdc++.h> using namespace std; const int MAXN = 1005; vector<vector<int> > adjlist; int memo[MAXN][MAXN][2]; int dfs(int cur, int prev, int k, int confidence[]) { if (memo[cur][prev][k]) return memo[cur][prev][k]; int ans = 0; for (auto &nx : adjlist[cur]) { if (nx == prev) continue; ans += dfs(nx, cur, 1, confidence); } if (k == 0) return ans; int res = confidence[cur]; for (auto &nx : adjlist[cur]) { if (nx == prev) continue; res += dfs(nx, cur, 0, confidence); } return memo[cur][prev][k] = max(ans, res); } int findSample(int n, int confidence[], int host[], int protocol[]) { adjlist.resize(n); bool subtask2 = 1, subtask3 = 1, subtask4 = 1; for (int i=1; i<n; i++) { if (protocol[i] != 1) subtask2 = 0; if (protocol[i] != 2) subtask3 = 0; if (protocol[i] != 0) subtask4 = 0; } if (subtask2) { int ans=0; for (int i=0; i<n; i++) ans += confidence[i]; return ans; } if (subtask3) { int ans=0; for (int i=0; i<n; i++) ans = max(ans, confidence[i]); return ans; } for (int i=1; i<n; i++) { if (protocol[i] != 1) { adjlist[host[i]].push_back(i); adjlist[i].push_back(host[i]); } if (protocol[i] != 0) { for (auto &nx : adjlist[host[i]]) { adjlist[i].push_back(nx); adjlist[nx].push_back(i); } } } if (subtask4) { return dfs(0, -1, 1, confidence); } int ans=0; for (int i=0; i<(1<<n); i++) { bool vis[n]; memset(vis, 0, sizeof(vis)); bool flag=1; int res=0; for (int j=0; j<n&&flag; j++) { int bit = (i>>j)&1; if (bit == 0) continue; res += confidence[j]; for (auto &nx : adjlist[j]) if (vis[nx]) flag = 0; vis[j] = 1; } if (flag) ans = max(ans, res); } return ans; }

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

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:12:23: warning: array subscript -1 is below array bounds of 'int [1005][2]' [-Warray-bounds]
   12 |     if (memo[cur][prev][k]) return memo[cur][prev][k];
      |         ~~~~~~~~~~~~~~^
#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...