제출 #806530

#제출 시각아이디문제언어결과실행 시간메모리
806530tolbi친구 (IOI14_friend)C++17
46 / 100
27 ms9548 KiB
#pragma optimize("Bismillahirrahmanirrahim") //█▀█─█──█──█▀█─█─█ //█▄█─█──█──█▄█─█■█ //█─█─█▄─█▄─█─█─█─█ //Allahuekber //ahmet23 orz... //FatihSultanMehmedHan //YavuzSultanSelimHan //AbdulhamidHan //Sani buyuk Osman Pasa Plevneden cikmam diyor #define author tolbi #include <bits/stdc++.h> using namespace std; template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr) {return os<<pr.first<<" "<<pr.second;} template<typename X> ostream& operator<<(ostream& os, vector<X> v){for (auto &it : v) os<<it<<" ";return os;} template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> v){for (auto &it : v) os<<it<<" ";return os;} ostream& operator<<(ostream& os, bool bl){return os<<(int32_t)bl;} #define endl '\n' #define deci(x) int x;cin>>x; #define decstr(x) string x;cin>>x; #define cinarr(x) for(auto &it : x) cin>>it; #define coutarr(x) for(auto &it : x) cout<<it<<" ";cout<<endl; #define sortarr(x) sort(x.begin(), x.end()) #define sortrarr(x) sort(x.rbegin(), x.rend()) #define rev(x) reverse(x.begin(), x.end()) #define tol(bi) (1ll<<((int)(bi))) typedef long long ll; const ll INF = LONG_LONG_MAX; const ll MOD = 1e9+9; mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count()); #include "friend.h" int findSample(int n,int confidence[],int host[],int protocol[]){ bool subt2=true,subt3=true,subt4=true; if (n<=10){ vector<vector<int>> arr(n); for (int i = 1; i < n; ++i) { int j = host[i]; if (protocol[i]==0){ arr[i].push_back(j); arr[j].push_back(i); } else if (protocol[i]==1){ for (int k = 0; k < arr[j].size(); k++){ int ele = arr[j][k]; arr[i].push_back(ele); arr[ele].push_back(i); } } else { for (int k = 0; k < arr[j].size(); k++){ int ele = arr[j][k]; arr[i].push_back(ele); arr[ele].push_back(i); } arr[i].push_back(j); arr[j].push_back(i); } } vector<vector<bool>> vis(n,vector<bool>(n,false)); for (int i = 0; i < n; ++i) { for (int j = 0; j < arr[i].size(); j++){ vis[i][arr[i][j]]=true; } } ll ans = 0; for (int i = 0; i < tol(n); i++){ ll somma = 0; bool valid = true; for (int j = 0; j < n; j++){ if (tol(j)&i) continue; somma+=confidence[j]; for (int k = 0; k < n; k++){ if (k==j) continue; if (tol(k)&i) continue; if (vis[j][k]){ valid=false; break; } } if (!valid) break; } if (valid) ans=max(ans,somma); } return ans; } for (int i = 1; i < n; ++i) { if (protocol[i]!=0) subt4=false; if (protocol[i]!=1) subt2=false; if (protocol[i]!=2) subt3=false; } if (subt4){ vector<vector<int>> arr(n); for (int i = 1; i < n; i++){ arr[i].push_back(host[i]); arr[host[i]].push_back(i); } vector<vector<ll>> dp(n,vector<ll>(2,-1)); auto dfs = [&](int node, int lnode, int flag, auto dfs)->ll{ if (dp[node][flag]!=-1) return dp[node][flag]; ll alirsam=confidence[node]; ll almazsam=0; for (int i = 0; i < arr[node].size(); i++){ if (arr[node][i]==lnode) continue; almazsam+=dfs(arr[node][i],node,0,dfs); alirsam+=dfs(arr[node][i],node,1,dfs); } if (flag) return dp[node][flag]=almazsam; return dp[node][flag]=max(alirsam,almazsam); }; return dfs(0,-1,0,dfs); } else if (subt3){ ll ans=0; for (int i = 0; i < n; ++i) { ans=max(ans,(ll)confidence[i]); } return ans; } else if (subt2){ ll ans = 0; for (int i = 0; i < n; ++i) { ans+=confidence[i]; } return ans; } //subtask 5 vector<int> dp(n,-1); vector<bool> valid(n,true); vector<vector<int>> arr(n); for (int i = 1; i < n; i++){ if (protocol[i]==0){ arr[host[i]].push_back(i); arr[i].push_back(host[i]); } else { for (int j = 0; j < arr[host[i]].size(); j++){ arr[i].push_back(arr[host[j]][i]); arr[arr[host[j]][i]].push_back(i); } } } int ans = 0; for (int i = 0; i < n; i++){ if (arr[i].size()==1){ valid[i]=false; valid[arr[i][0]]=false; ans++; } } vector<int> stk; auto f = [&](int node, auto f)->void{ for (int i = 0; i < arr[node].size(); i++){ if (dp[arr[node][i]]!=-1) continue; dp[arr[node][i]]=dp[node]^1; f(arr[node][i],f); } }; dp[0]=0; f(0,f); int crrw = 0; int crrb = 0; for (int node = 0; node < n; node++){ if (!valid[node]) continue; if (dp[node]) crrw++; else crrb++; } ans+=max(crrw,crrb); return ans; }

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

friend.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int k = 0; k < arr[j].size(); k++){
      |                     ~~^~~~~~~~~~~~~~~
friend.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int k = 0; k < arr[j].size(); k++){
      |                     ~~^~~~~~~~~~~~~~~
friend.cpp:63:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |    for (int j = 0; j < arr[i].size(); j++){
      |                    ~~^~~~~~~~~~~~~~~
friend.cpp:141:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |    for (int j = 0; j < arr[host[i]].size(); j++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
friend.cpp: In instantiation of 'findSample(int, int*, int*, int*)::<lambda(int, int, int, auto:23)> [with auto:23 = findSample(int, int*, int*, int*)::<lambda(int, int, int, auto:23)>; ll = long long int]':
friend.cpp:113:24:   required from here
friend.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |    for (int i = 0; i < arr[node].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~~
friend.cpp: In instantiation of 'findSample(int, int*, int*, int*)::<lambda(int, auto:24)> [with auto:24 = findSample(int, int*, int*, int*)::<lambda(int, auto:24)>]':
friend.cpp:164:7:   required from here
friend.cpp:157:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |   for (int i = 0; i < arr[node].size(); i++){
      |                   ~~^~~~~~~~~~~~~~~~~~
#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...