# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
430860 |
2021-06-17T07:11:40 Z |
errorgorn |
Friend (IOI14_friend) |
C++17 |
|
9 ms |
11596 KB |
//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int NORMAL=0; //normal friendship
const int COPY1=1; //both itself and parent can be on
const int COPY2=2; //either itself or parent must be off
const int DUP=3; //copy of certain node
int n;
int arr[100005];
vector<ii> al[200005];
int val[200005];
int id[100005];
int IDX=1;
int memo[200005][2][2][2];
//for a normal friendship edge, for the guy to be toggled
//everyone connected by copy/dup edges must be toggled off
//for copy2 edges, all subtrees with copy2 edge but all be off
//if you are on, all parents traversed by copy edges shld be togglable
//states:
// b1: anyone in your copy CC toggled
// b2: anyone in copy1 CC toggled
// b3: are you toggled
//if there is someone in your copy CC toggled
//anyone connected by normal edges cannot have their copy CC toggled
//you also need to be same toggle as duplicate if yourself if it exists
int dp(int i,int b1,int b2,int b3){
if (memo[i][b1][b2][b3]!=-1) return memo[i][b1][b2][b3];
int res=0;
if (b3) res+=val[i];
if (b3 && (!b1 || !b2)) return memo[i][b1][b2][b3]=-1e9;
for (auto &it:al[i]){
if (it.se==DUP){
res+=dp(it.fi,b1,b2,b3);
}
if (it.se==NORMAL){
if (b1) res+=dp(it.fi,0,0,0);
else{
int temp=0;
rep(x,0,2) rep(y,0,2) rep(z,0,2)
temp=max(temp,dp(it.fi,x,y,z));
res+=temp;
}
}
if (it.se==COPY1){
res+=max(dp(it.fi,b1,b2,0),dp(it.fi,b1,b2,1));
}
if (it.se==COPY2){
if (b3) res+=dp(it.fi,b1,0,0);
else{
int temp=0;
rep(y,0,2) rep(z,0,2)
temp=max(temp,dp(it.fi,b1,y,z));
res+=temp;
}
}
}
return memo[i][b1][b2][b3]=res;
}
int findSample(int N,int confidence[],int host[],int protocol[]){
n=N;
rep(x,0,n) arr[x]=confidence[x];
id[0]=0;
rep(x,1,n){
int h=host[x];
if (protocol[x]==0){
al[id[h]].pub(ii(IDX,DUP));
id[h]=IDX++;
al[id[h]].pub(ii(IDX,NORMAL));
id[x]=IDX++;
}
else if (protocol[x]==1){
al[id[h]].pub(ii(IDX,COPY1));
id[x]=IDX++;
}
else{
al[id[h]].pub(ii(IDX,DUP));
id[h]=IDX++;
al[id[h]].pub(ii(IDX,COPY2));
id[x]=IDX++;
}
}
//rep(x,0,n) cout<<id[x]<<" "; cout<<endl;
rep(x,0,n) val[id[x]]=arr[x];
memset(memo,-1,sizeof(memo));
int ans=0;
rep(x,0,2) rep(y,0,2) rep(z,0,2){
//cout<<x<<" "<<y<<" "<<z<<" "<<dp(0,x,y,z)<<endl;
ans=max(ans,dp(0,x,y,z));
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11212 KB |
Output is correct |
2 |
Correct |
8 ms |
11284 KB |
Output is correct |
3 |
Correct |
8 ms |
11276 KB |
Output is correct |
4 |
Correct |
7 ms |
11212 KB |
Output is correct |
5 |
Correct |
7 ms |
11212 KB |
Output is correct |
6 |
Correct |
7 ms |
11212 KB |
Output is correct |
7 |
Correct |
8 ms |
11284 KB |
Output is correct |
8 |
Incorrect |
8 ms |
11212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11288 KB |
Output is correct |
2 |
Correct |
7 ms |
11232 KB |
Output is correct |
3 |
Correct |
7 ms |
11212 KB |
Output is correct |
4 |
Correct |
7 ms |
11320 KB |
Output is correct |
5 |
Correct |
8 ms |
11340 KB |
Output is correct |
6 |
Correct |
8 ms |
11260 KB |
Output is correct |
7 |
Correct |
8 ms |
11304 KB |
Output is correct |
8 |
Correct |
8 ms |
11324 KB |
Output is correct |
9 |
Correct |
7 ms |
11212 KB |
Output is correct |
10 |
Correct |
8 ms |
11212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
11212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11212 KB |
Output is correct |
2 |
Correct |
7 ms |
11212 KB |
Output is correct |
3 |
Correct |
7 ms |
11284 KB |
Output is correct |
4 |
Correct |
8 ms |
11212 KB |
Output is correct |
5 |
Correct |
9 ms |
11596 KB |
Output is correct |
6 |
Correct |
8 ms |
11340 KB |
Output is correct |
7 |
Correct |
8 ms |
11212 KB |
Output is correct |
8 |
Correct |
8 ms |
11340 KB |
Output is correct |
9 |
Correct |
9 ms |
11248 KB |
Output is correct |
10 |
Correct |
8 ms |
11288 KB |
Output is correct |
11 |
Correct |
9 ms |
11312 KB |
Output is correct |
12 |
Correct |
9 ms |
11340 KB |
Output is correct |
13 |
Correct |
9 ms |
11340 KB |
Output is correct |
14 |
Correct |
8 ms |
11296 KB |
Output is correct |
15 |
Correct |
8 ms |
11340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11216 KB |
Output is correct |
2 |
Correct |
7 ms |
11280 KB |
Output is correct |
3 |
Correct |
7 ms |
11280 KB |
Output is correct |
4 |
Correct |
7 ms |
11288 KB |
Output is correct |
5 |
Correct |
8 ms |
11212 KB |
Output is correct |
6 |
Correct |
7 ms |
11280 KB |
Output is correct |
7 |
Correct |
7 ms |
11212 KB |
Output is correct |
8 |
Correct |
7 ms |
11212 KB |
Output is correct |
9 |
Correct |
8 ms |
11596 KB |
Output is correct |
10 |
Correct |
8 ms |
11468 KB |
Output is correct |
11 |
Incorrect |
7 ms |
11212 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11280 KB |
Output is correct |
2 |
Correct |
7 ms |
11280 KB |
Output is correct |
3 |
Correct |
8 ms |
11284 KB |
Output is correct |
4 |
Correct |
7 ms |
11212 KB |
Output is correct |
5 |
Correct |
7 ms |
11288 KB |
Output is correct |
6 |
Correct |
7 ms |
11284 KB |
Output is correct |
7 |
Incorrect |
7 ms |
11212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |