# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874038 |
2023-11-16T08:13:03 Z |
hmm789 |
Friend (IOI14_friend) |
C++14 |
|
40 ms |
65536 KB |
#include <bits/stdc++.h>
#include "friend.h"
using namespace std;
int memo[1000][2], c[1000];
vector<int> adj[1000];
int dp(int x, int f) {
if(memo[x][f] != -1) return memo[x][f];
int ans = (f==1?c[x]:0);
for(int i : adj[x]) {
if(f == 1) ans += dp(i, 0);
else ans += max(dp(i, 0), dp(i, 1));
}
return memo[x][f] = ans;
}
int findSample(int n, int confidence[], int host[], int protocol[]) {
bool st2 = true, st3 = true, st4 = true, st5 = true;
for(int i = 0; i < n; i++) c[i] = confidence[i];
for(int i = 1; i < n; i++) {
if(protocol[i] != 0) st4 = false;
if(protocol[i] != 1) st2 = false;
if(protocol[i] != 2) st3 = false;
if(protocol[i] == 2) st5 = false;
}
if(st2) {
int sm = 0;
for(int i = 0; i < n; i++) sm += confidence[i];
return sm;
} else if(st3) {
int mx = 0;
for(int i = 0; i < n; i++) mx = max(mx, confidence[i]);
return mx;
}
for(int i = 1; i < n; i++) {
if(protocol[i] != 0) {
for(int x : adj[host[i]]) {
adj[x].push_back(i);
adj[i].push_back(x);
}
} else if(protocol[i] != 1) {
adj[i].push_back(host[i]);
adj[host[i]].push_back(i);
}
}
if(st4) {
memset(memo, -1, sizeof(memo));
return max(dp(0, 0), dp(0, 1));
} else if(st5) {
int ans[2], dist[n];
ans[0] = ans[1] = 0;
memset(dist, -1, sizeof(dist));
dist[0] = 0;
ans[0] += c[0];
queue<int> q;
q.push(0);
while(!q.empty()) {
int cur = q.front();
q.pop();
for(int i : adj[cur]) {
if(dist[i] != -1) continue;
dist[i] = dist[cur]^1;
ans[dist[i]] += c[i];
}
}
return max(ans[0], ans[1]);
} else {
int am[n][n], ans = 0;
memset(am, 0, sizeof(am));
for(int i = 0; i < n; i++) {
for(int j : adj[i]) am[i][j] = 1;
}
for(int i = 0; i < 1<<n; i++) {
vector<int> v;
for(int j = 0; j < n; j++) {
if(i&(1<<j)) v.push_back(j);
}
int sm = 0;
for(int j = 0; j < v.size(); j++) {
for(int k = j+1; k < v.size(); k++) {
if(am[v[j]][v[k]]) goto ed;
}
}
for(int j = 0; j < v.size(); j++) sm += c[v[j]];
ans = max(ans, sm);
ed:;
}
return ans;
}
}
Compilation message
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:79:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int j = 0; j < v.size(); j++) {
| ~~^~~~~~~~~~
friend.cpp:80:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int k = j+1; k < v.size(); k++) {
| ~~^~~~~~~~~~
friend.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int j = 0; j < v.size(); j++) sm += c[v[j]];
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
516 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
40 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
38 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
39 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |