제출 #490270

#제출 시각아이디문제언어결과실행 시간메모리
490270fcmalkcinSplit the Attractions (IOI19_split)C++17
0 / 100
4 ms5324 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll  int
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=1e5+50;
const ll mod=1e9+7  ;
const ll base=2e18;
/// you will be the best but now you just are trash
/// goal 6/7
vector<ll> adj[maxn];
vector<pll> nw;
vector<ll> adj1[maxn];
ll siz[maxn];
ll low[maxn];
ll num[maxn];
ll cntnw=0;
ll pos=-1;
ll anc[maxn];
void dfs(ll u)
{
    cntnw++;
    low[u]=cntnw;
    num[u]=cntnw;
    siz[u]=1;
    bool chk=true;
    for (auto to:adj[u])
    {
        if (num[to])
        {
            low[u]=min(low[u],num[to]);
            continue;
        }
        adj1[u].pb(to);
        adj1[to].pb(u);
        anc[to]=u;
        dfs(to);
        low[u]=min(low[u],low[to]);
        siz[u]+=siz[to];
        if (siz[to]>=nw[0].ff) chk=false;
    }
    if (chk&&siz[u]>=nw[0].ff)
    {
        pos=u;
    }
}
vector<ll> ans;
ll colmx;
ll cnt[4];
ll val[4];
ll dem=0;
void dfs1(ll u,ll col1)
{
   // cout <<siz[u]<<" chk"<<endl;
    if (cnt[col1]>=val[col1]) col1=colmx;
    ans[u]=col1;
    cnt[col1]++;
   // assert(cnt[col1]<=val[col1]);
    for (auto to:adj1[u])
    {
        if (to==anc[u]||ans[to]) continue;
        dfs1(to,col1);
    }
}
void dfs2(ll u,ll col2)
{
    if (cnt[col2]<val[col2]) col2=colmx;
    ans[u]=col2;
    cnt[col2]++;
  //  assert(cnt[col2]<=val[col2]);
    for (auto to:adj[u])
    {
        if (ans[to]) continue;
        dfs2(to,col2);
    }
}
vector<ll> find_split(int n, int a, int b, int c, vector<ll> p, vector<ll> q)
{
    memset(anc,-1,sizeof(anc));
    nw.pb(make_pair(a,1));
    nw.pb(make_pair(b,2));
    nw.pb(make_pair(c,3));
    sort(nw.begin(),nw.end());
    for (int i=1;i<=nw.size();i++) val[nw[i-1].ss]=nw[i-1].ff;
    colmx=nw.back().ss;
    for (int i=0;i<p.size();i++)
    {
        adj[p[i]].pb(q[i]);
        adj[q[i]].pb(p[i]);
    }
    ans=vector<ll> (n,0);
    dfs(0);
    ll cl=siz[pos];
    ll u=pos;
    ll h=n-cl;
  ll kp=nw[0].ff;
    for (int i=0;i<adj1[u].size();i++)
    {
        ll to=adj1[u][i];
        if (to==anc[u]) continue;
        if (low[to]<num[u])
        {
            if (cl-siz[to]>=kp)
            {
                h+=siz[to];
                cl-=siz[to];
            }
            else
            {
                break;
            }
        }
        else
        {
        }
    }
    if (h<nw[0].ff)
    {
        ans=vector<ll> (n,0);
        return ans;
    }
    if (h<cl)
    {
        swap(nw[0],nw[1]);
    }
    cl=siz[pos];
     ans[pos]=nw[0].ss;
    cnt[nw[0].ss]++;
    for (int i=0;i<adj1[u].size();i++)
    {
        ll to=adj1[u][i];
        if (to==anc[u]) continue;
        if (low[to]<num[u])
        {
            if (cl-siz[to]>=kp)
            {

                h+=siz[to];
                cl-=siz[to];
            }
            else
            {
                for (int j=i;j<adj1[u].size();j++)
                {
                    ll to=adj1[u][j];
                    if (to==anc[u]||ans[to]) continue;
                    dfs1(to,nw[0].ss);
                }
                break;
            }
        }
        else
        {
            dfs1(to,nw[0].ss);
        }
    }
    if (anc[u]!=-1)
    {
        dfs2(anc[u],nw[1].ss);
    }
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

split.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization("unroll-loops, no-stack-protector")
      | 
split.cpp:18:15: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
   18 | const ll base=2e18;
      |               ^~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:94:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (int i=1;i<=nw.size();i++) val[nw[i-1].ss]=nw[i-1].ff;
      |                  ~^~~~~~~~~~~
split.cpp:96:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for (int i=0;i<p.size();i++)
      |                  ~^~~~~~~~~
split.cpp:107:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     for (int i=0;i<adj1[u].size();i++)
      |                  ~^~~~~~~~~~~~~~~
split.cpp:139:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |     for (int i=0;i<adj1[u].size();i++)
      |                  ~^~~~~~~~~~~~~~~
split.cpp:153:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |                 for (int j=i;j<adj1[u].size();j++)
      |                              ~^~~~~~~~~~~~~~~
#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...