이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "friend.h"
#define LINE "------------\n"
#define ALL(x) x.begin(),x.end()
#define LLA(x) x.rbegin(),x.rend()
#define pb push_back
using namespace std;
using PII = pair <int, int>;
using ll = long long;
// Find out best sample
/*
0 for IAmYourFriend,
1 for MyFriendsAreYourFriends,
2 for WeAreYourFriends.
*/
const int N = 1e3 + 5;
set <int> friends[N];
void IAmYourFriend(int x, int y) {
// cout << "IAmYourFriend: " << x << ' ' << y <<'\n';
friends[x].insert(y);
friends[y].insert(x);
}
void MyFriendsAreYourFriends(int x, int y) {
// cout << "MyFriendsAreYourFriends: " << x << ' ' << y <<'\n';
for (auto el : friends[y]) IAmYourFriend(el, x);
}
void WeAreYourFriends(int x, int y) {
// cout << "WeAreYourFriends: " << x << ' ' << y <<'\n';
MyFriendsAreYourFriends(x, y);
IAmYourFriend(x, y);
}
bool isFriend[N][N];
int findSample(int n, int nums[], int host[], int type[]){
for (int i = 1; i < n; i++) {
if (type[i] == 0) IAmYourFriend(i, host[i]);
else if (type[i] == 1) MyFriendsAreYourFriends(i, host[i]);
else WeAreYourFriends(i, host[i]);
}
for (int i = 0; i < n; i++) {
// cout << i << ": ";
for (auto el : friends[i]) {
// cout << el << ' ';
isFriend[i][el] = 1;
}
// cout << "\n";
}
int ans = 0;
for (int i = 0; i < (1<<n); i++) {
vector <int> ids;
for (int j = 0; j < n; j++) {
if (i & (1<<j)) ids.pb(j);
}
bool no = 0;
for (auto el : ids)
for (auto el1 : ids) {
no |= isFriend[el][el1];
}
if (no) continue;
int sum = 0;
for (auto el : ids) {
// cout << el <<" ";
sum += nums[el];
}
// cout << ": " << sum << '\n';
ans = max(ans, sum);
}
return ans;
}
# | 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... |