제출 #1017752

#제출 시각아이디문제언어결과실행 시간메모리
1017752simona1230친구 (IOI14_friend)C++17
46 / 100
21 ms9180 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; int c[100001]; int p[100001]; int t[100001]; int n; vector<int> v[1024]; bool in[1024]; int brute; void check() { int sum=0; bool pos=1; for(int i=0;i<n;i++) { if(in[i])sum+=c[i]; for(int j=0;j<v[i].size();j++) { int nb=v[i][j]; if(in[i]&&in[nb])pos=0; } } if(!pos)return; brute=max(brute,sum); } int dp[100001][2]; void dfs(int i,int pr) { for(int j=0;j<v[i].size();j++) { int nb=v[i][j]; if(pr==nb)continue; dfs(nb,i); dp[i][0]+=max(dp[nb][1],dp[nb][0]); dp[i][1]+=dp[nb][0]; } dp[i][1]+=c[i]; } void rec(int i) { if(i==n) { check(); return; } in[i]=1; rec(i+1); in[i]=0; rec(i+1); } int used[100001],here,all,comp; void dfs1(int i,int p) { comp++; if(p==-1||used[p]==1) { used[i]=2; here++; } else used[i]=1; for(int j=0;j<v[i].size();j++) { int nb=v[i][j]; if(!used[nb]) { dfs1(nb,i); } } } int findSample(int N,int confidence[],int host[],int protocol[]) { n=N; int sum=0,maxx=0; for(int i=0;i<n;i++) { t[i]=protocol[i]; //cout<<"- "<<t[i]<<endl; c[i]=confidence[i]; p[i]=host[i]; sum+=c[i]; maxx=max(maxx,c[i]); if(i==0)continue; if(t[i]==2||t[i]==0) { v[i].push_back(p[i]); v[p[i]].push_back(i); } if(t[i]==2||t[i]==1) { for(int j=0;j<v[p[i]].size();j++) { int nb=v[p[i]][j]; if(nb==i)continue; v[nb].push_back(i); v[i].push_back(nb); } } } /*for(int i=0;i<n;i++) { cout<<i<<": "; for(int j=0;j<v[i].size();j++) { cout<<v[i][j]<<" "; } cout<<endl; }*/ if(n<=10) { rec(0); return brute; } //cout<<sum<<endl; bool o1=1; for(int i=1;i<n;i++) if(t[i]!=1)o1=0; //cout<<o1<<endl; if(o1==1)return sum; bool o2=1; for(int i=1;i<n;i++) if(t[i]!=2)o2=0; if(o2==1)return maxx; bool o0=1; for(int i=1;i<n;i++) if(t[i]!=0)o0=0; if(o0==1) { dfs(0,-1); return max(dp[0][1],dp[0][0]); } for(int i=0;i<n;i++) { if(!used[i]) { here=comp=0; dfs1(i,-1); all+=max(here,comp-here); } } return all; }

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

friend.cpp: In function 'void check()':
friend.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for(int j=0;j<v[i].size();j++)
      |                     ~^~~~~~~~~~~~
friend.cpp: In function 'void dfs(int, int)':
friend.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int j=0;j<v[i].size();j++)
      |                 ~^~~~~~~~~~~~
friend.cpp: In function 'void dfs1(int, int)':
friend.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int j=0;j<v[i].size();j++)
      |                 ~^~~~~~~~~~~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:99:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |             for(int j=0;j<v[p[i]].size();j++)
      |                         ~^~~~~~~~~~~~~~~
friend.cpp:132:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  132 |     for(int i=1;i<n;i++)
      |     ^~~
friend.cpp:134:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  134 |  if(o2==1)return maxx;
      |  ^~
#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...