제출 #1063855

#제출 시각아이디문제언어결과실행 시간메모리
1063855kkzyr친구 (IOI14_friend)C++17
46 / 100
22 ms2960 KiB
#include <iostream> #include <vector> using namespace std; bool a[10]; int answer; vector<int> adj[1000]; void brute_force(int n, int confidence[], int choose, bool used[], int total_sum){ if (choose == n){ if (total_sum > answer){ answer = total_sum; } return; } brute_force(n, confidence, choose + 1, used, total_sum); bool ok_add = true; for (int i = 0;i < adj[choose].size();i++){ if (used[adj[choose][i]]){ ok_add = false; } } if (ok_add){ used[choose] = true; brute_force(n, confidence, choose + 1, used, total_sum + confidence[choose]); used[choose] = false; } } int done[1000]; int dp[1000][2]; void do_dp(int node, int confidence[]){ done[node] = true; dp[node][1] = confidence[node]; for (int i = 0;i < adj[node].size();i++){ int child = adj[node][i]; if (!done[child]){ do_dp(child, confidence); dp[node][0] += max(dp[child][0], dp[child][1]); dp[node][1] += dp[child][0]; } } } int parent[1000]; int ans_taken[1000]; void init(int n){ for (int i = 0;i < n;i++){ parent[i] = -1; } } int find(int x){ if (parent[x] == -1){ return x; } parent[x] = find(parent[x]); return parent[x]; } void merge(int x, int y){ int component1 = find(x); int component2 = find(y); if (component1 != component2){ parent[component1] = component2; } } int findSample(int n, int confidence[], int host[], int protocol[]){ if (n <= 10){ for (int i = 1;i < n;i++){ if (protocol[i] == 0){ adj[host[i]].push_back(i); adj[i].push_back(host[i]); } else if (protocol[i] == 1){ for (int j = 0;j < adj[host[i]].size();j++){ int child = adj[host[i]][j]; adj[child].push_back(i); adj[i].push_back(child); } } else{ adj[host[i]].push_back(i); adj[i].push_back(host[i]); for (int j = 0;j < adj[host[i]].size();j++){ int child = adj[host[i]][j]; adj[child].push_back(i); adj[i].push_back(child); } } } brute_force(n, confidence, 0, a, 0); return answer; } bool all_one_kind = true; for (int i = 1;i < n - 1;i++){ if (protocol[i] != protocol[i + 1]){ all_one_kind = false; break; } } if (all_one_kind and protocol[1] == 0){ for (int i = 0;i < n;i++){ adj[host[i]].push_back(i); adj[i].push_back(host[i]); } do_dp(0, confidence); return max(dp[0][0], dp[0][1]); } else if (all_one_kind and protocol[1] == 1){ int sum = 0; for (int i = 0;i < n;i++){ sum += confidence[i]; } return sum; } else{ init(n); for (int i = 1;i < n;i++){ merge(host[i], i); } for (int i = 0;i < n;i++){ ans_taken[find(i)] = max(ans_taken[find(i)], confidence[i]); } int sum = 0; for (int i = 0;i < n;i++){ sum += ans_taken[i]; } return sum; } }

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

friend.cpp: In function 'void brute_force(int, int*, int, bool*, int)':
friend.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0;i < adj[choose].size();i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~
friend.cpp: In function 'void do_dp(int, int*)':
friend.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i = 0;i < adj[node].size();i++){
      |                    ~~^~~~~~~~~~~~~~~~~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:80:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                 for (int j = 0;j < adj[host[i]].size();j++){
      |                                ~~^~~~~~~~~~~~~~~~~~~~~
friend.cpp:89:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |                 for (int j = 0;j < adj[host[i]].size();j++){
      |                                ~~^~~~~~~~~~~~~~~~~~~~~
#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...