Submission #737150

#TimeUsernameProblemLanguageResultExecution timeMemory
737150ammar2000Split the Attractions (IOI19_split)C++17
22 / 100
659 ms1048576 KiB
#include "split.h"
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define dp st
#define F first
#define S second
#define coy cout<<"YES\n"
#define con cout<<"NO\n"
#define co1 cout<<"-1\n"
#define sc(x) scanf("%lld",&x)
#define all(x) x.begin(),x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int SI=3e5+7;
ll INF=8e18+7;
int MOD=1e9+7;
vector<int> ret;
bool fou=0;
vector <ll> v[SI];
int nn, aa,bb,cc;
int p[SI],st[SI];
void bt(int x=1,int pa=0)
{
    p[x]=pa;
    st[x]=1;
    for(auto i:v[x])
    {
        if (i==pa)
            continue;
        bt(i,x);
        st[x]+=st[i];
    }
}
int hmtc=0;
void dfs(int x,int pa ,int col)
{
    if (hmtc<=0)
        return ;
    ret[x-1]=col;
    hmtc--;
    for(auto i:v[x])
        if(i!=pa)
          dfs(i,x,col);
}
void bld(int x,int i,int o,bool k)
{
    if (fou)
        return ;
    fou=1;
    int re;
    vector <ll> ss(2),ee(2);
    if (o==0)
    ss={bb,cc},ee={2,3},re=1;
    else if (o==1)
    ss={aa,cc},ee={1,3},re=2;
    else ss={bb,cc},ee={1,2},re=3;
    if (k)
    swap(ss[0],ss[1]),swap(ee[0],ee[1]);
    hmtc=ss[0];
    dfs(i,x,ee[0]);
    hmtc=ss[1];
    dfs(x,i,ee[1]);
    for(int i=0;i<nn;i++)
        if(ret[i]==0)
          ret[i]=re;
}

void fans(int x=1,int pa=0)
{
    if (x!=1)
    {st[pa]-=st[x];
    st[x]+=st[pa];}
   // cout <<x<<" " <<pa <<"\n";
    for (int o=0;o<3;o++)
    {
        vector <ll> ss(2);
        if (o==0)
        ss={bb,cc};
        else if (o==1)
        ss={aa,cc};
        else ss={bb,cc};
       for (auto i:v[x])
       {
        //   cout << dp[i]<<" " <<ss[0]<<" " <<dp[x]<<" " <<ss[1]<<"\n";
         if (dp[i]>=ss[0]&&dp[x]-dp[i]>=ss[1])
            bld(x,i,o,0);
         else if (dp[i]>=ss[1]&&dp[x]-dp[i]>=ss[1])
            bld(x,i,o,1);
       }
    }
    for(auto i:v[x])
        if (i!=pa)
            fans(i,x);
    if (x!=1)
    {st[x]-=st[pa];
    st[pa]+=st[x];
    }
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
	ret.resize(n);
	for(int i=0;i<p.size();i++)
    {
        int d=p[i],m=q[i];
        d++;
        m++;
        v[d].pb(m);
        v[m].pb(d);
    }
    aa=a;
    bb=b;
    cc=c;
    nn=n;
	bt();

	fans();
	return ret;
}

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:102:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |  for(int i=0;i<p.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...