이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
for (int i = 1; i < n; ++i)
{
if (protocol[i]!=0) subt4=false;
else if (protocol[i]!=1) subt2=false;
else 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;
}
vector<bitset<10>> arr(n);
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < 10; j++){
arr[i][j]=1;
}
arr[i][i]=0;
}
for (int i = 1; i < n; i++){
int j = host[i];
if (protocol[i]==0){//IAmYourFriend
arr[i][j]=0;
arr[j][i]=0;
}
else if (protocol[i]==1){//MyFriendsAreYourFriend
for (int k = 0; k < 10; k++){
if (k==j) continue;
if (arr[k][j]==0){
arr[i][k]=arr[k][i]=0;
}
}
}
else {//WeAreYourFriends
for (int k = 0; k < 10; k++){
if (arr[k][j]==0){
arr[i][k]=arr[k][i]=0;
}
}
}
}
auto dfs = [&](bitset<10> bs, auto dfs)->ll{
ll rval = 0;
for (int i = 0; i < 10; i++){
if (bs[i]==0) continue;
bs[i]=0;
bitset<10> ns = bs&arr[i];
rval=max(rval,(ll)confidence[i]+dfs(ns,dfs));
}
return rval;
};
bitset<10> full;
for (int i = 0; i < n; ++i)
{
full[i]=1;
}
return dfs(full,dfs);
}
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
1 | #pragma optimize("Bismillahirrahmanirrahim")
|
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:59:30: required from here
friend.cpp:51:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 0; i < arr[node].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |