Submission #931374

# Submission time Handle Problem Language Result Execution time Memory
931374 2024-02-21T16:49:20 Z HuyQuang_re_Zero Mechanical Doll (IOI18_doll) C++14
0 / 100
7 ms 33372 KB
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define maxn 1000005
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define IDB pair <db,int>
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x)
#include "doll.h"
using namespace std;
int s,i,n,m,numa[maxn],numb[maxn],k,num[maxn],a[maxn];
vector <int> res,X,Y,to[maxn];
/*
void answer(vector <int> res,vector <int> X,vector <int> Y)
{
    for(int x:res) cout<<x<<'\n';
    for(int i=0;i<s;i++) cout<<X[i]<<" "<<Y[i]<<'\n';
}*/
struct Graph
{
    int n=0;
    vector <int> X,Y;
    vector <II> sink;
};
Graph cal(int n)
{
    Graph res;
    if(n==2)
    {
        res.n=1;
        res.X.push_back(0); res.X.push_back(-1);
        res.Y.push_back(0); res.Y.push_back(-1);
        res.sink.push_back({ 1,0 });
        res.sink.push_back({ 1,1 });
        return res;
    }
    res.n=1;
    Graph a=cal((n+1)/2),b=a;
    res.X.resize(a.n+b.n+2);
    res.Y.resize(a.n+b.n+2);
    res.X[1]=res.n+1;
    for(int i=1;i<=a.n;i++) numa[i]=++res.n;
    for(int i=1;i<=a.n;i++)
    {
        res.X[numa[i]]=(a.X[i]>-1 ? numa[a.X[i]] : -1);
        res.Y[numa[i]]=(a.Y[i]>-1 ? numa[a.Y[i]] : -1);
    }
    res.Y[1]=res.n+1;
    for(int i=1;i<=b.n;i++) numb[i]=++res.n;
    for(int i=1;i<=b.n;i++)
    {
        res.X[numb[i]]=(b.X[i]>-1 ? numb[b.X[i]] : -1);
        res.Y[numb[i]]=(b.Y[i]>-1 ? numb[b.Y[i]] : -1);
    }
    if(n&1)
    {
        if(b.sink[b.sink.size()-2].snd==0)
            res.X[numb[b.sink[b.sink.size()-2].fst]]=1;
        else res.Y[numb[b.sink[b.sink.size()-2].fst]]=1;

        for(int i=0;i<a.sink.size()-2;i++)
        {
            res.sink.push_back({ numa[a.sink[i].fst],a.sink[i].snd });
            res.sink.push_back({ numb[b.sink[i].fst],b.sink[i].snd });
        }
        res.sink.push_back({ numa[a.sink[a.sink.size()-2].fst],a.sink[a.sink.size()-2].snd });
        res.sink.push_back({ numa[a.sink[a.sink.size()-1].fst],a.sink[a.sink.size()-1].snd });
        res.sink.push_back({ numb[b.sink[b.sink.size()-1].fst],b.sink[b.sink.size()-1].snd });
    }
    else
    {
        for(int i=0;i<a.sink.size();i++)
        {
            res.sink.push_back({ numa[a.sink[i].fst],a.sink[i].snd });
            res.sink.push_back({ numb[b.sink[i].fst],b.sink[i].snd });
        }
    }
    return res;
}
void sub1()
{
    for(k=1;k<=m;k++)
    {
        if(to[k].size()==1)
        {
            res[k]=to[k].back();
            continue;
        }
        if(to[k].size()==0)
        {
            res[k]=0;
            continue;
        }
        Graph G=cal(to[k].size());
        res[k]=-s-1;
        for(i=1;i<=G.n;i++) num[i]=++s;
        for(i=1;i<=G.n;i++)
        {
            X[num[i]-1]=-num[G.X[i]];
            Y[num[i]-1]=-num[G.Y[i]];
        }
        for(i=0;i<to[k].size();i++)
        {
            if(G.sink[i].snd==0)
                X[num[G.sink[i].fst]-1]=to[k][i];
            else Y[num[G.sink[i].fst]-1]=to[k][i];
        }
    }
    while(X.size()>s) X.pop_back();
    while(Y.size()>s) Y.pop_back();
    answer(res,X,Y);
}

void sub2()
{
    Graph G=cal(n);
    for(i=1;i<=m;i++) res[i]=-1;
    for(i=1;i<=G.n;i++)
    {
        X[i-1]=-G.X[i];
        Y[i-1]=-G.Y[i];
    }
    for(i=0;i<G.sink.size();i++)
        if(G.sink[i].snd==0)
            X[G.sink[i].fst-1]=a[i+2];
        else Y[G.sink[i].fst-1]=a[i+2];

    s=G.n;
    while(X.size()>s) X.pop_back();
    while(Y.size()>s) Y.pop_back();
    answer(res,X,Y);
}
void sub_same()
{
    Graph G=cal(n);
    res[m]=-1;
    int G_end=G.sink.back().fst;
    auto check=[&](int k)
    {
        return k!=G_end && G.X[k]==-1 && G.Y[k]==-1;
    };
    for(i=1;i<=G.n;i++)
        if(!check(i)) num[i]=++s;


    if(s!=G.n) s++,X[s-1]=Y[s-1]=1;


  //  cerr<<G.n<<" "<<s<<'\n';
    for(i=1;i<=G.n;i++)
    {
        if(check(i)) continue;
    //    cerr<<i<<'\n';
        if(G.X[i]==-1) X[num[i]-1]=1;
        else if(check(G.X[i])) X[num[i]-1]=-s;
        else X[num[i]-1]=-num[G.X[i]];

        if(G.Y[i]==-1) Y[num[i]-1]=1;
        else if(check(G.Y[i])) Y[num[i]-1]=-s;
        else Y[num[i]-1]=-num[G.Y[i]];
    }
   // cerr<<num[G_end]<<'\n';
    if(G.sink.back().snd==0)
        X[num[G_end]-1]=0;
    else Y[num[G_end]-1]=0;

    while(X.size()>s) X.pop_back();
    while(Y.size()>s) Y.pop_back();
    answer(res,X,Y);
}


void create_circuit(int _m,vector <int> _a)
{
    m=_m; n=_a.size();
    int ok=1;
    for(i=0;i<n;i++)
    {
        a[i+1]=_a[i];
        if(i+1<n) to[_a[i]].push_back(_a[i+1]);
        else to[_a[i]].push_back(0);
    }
    for(i=1;i<=m;i++)
        ok&=(to[i].size()<=4);
    res.resize(m+1);
    res[0]=a[1];
    X.resize(2*n); Y.resize(2*n);
    sub_same();
    exit(0);
    if(ok) sub1();
    else if(m==1) sub_same();
    else sub2();
}
/*
int main()
{
    freopen("doll.inp","r",stdin);
    freopen("doll.out","w",stdout);
    int m,n,k;
    cin>>m;
    vector <int> a;
    while(cin>>k) a.push_back(k);
    create_circuit(m,a);
}
*/

Compilation message

doll.cpp: In function 'Graph cal(int)':
doll.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int i=0;i<a.sink.size()-2;i++)
      |                     ~^~~~~~~~~~~~~~~~
doll.cpp:81:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(int i=0;i<a.sink.size();i++)
      |                     ~^~~~~~~~~~~~~~
doll.cpp: In function 'void sub1()':
doll.cpp:111:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |         for(i=0;i<to[k].size();i++)
      |                 ~^~~~~~~~~~~~~
doll.cpp:118:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  118 |     while(X.size()>s) X.pop_back();
      |           ~~~~~~~~^~
doll.cpp:119:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  119 |     while(Y.size()>s) Y.pop_back();
      |           ~~~~~~~~^~
doll.cpp: In function 'void sub2()':
doll.cpp:132:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |     for(i=0;i<G.sink.size();i++)
      |             ~^~~~~~~~~~~~~~
doll.cpp:138:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  138 |     while(X.size()>s) X.pop_back();
      |           ~~~~~~~~^~
doll.cpp:139:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  139 |     while(Y.size()>s) Y.pop_back();
      |           ~~~~~~~~^~
doll.cpp: In function 'void sub_same()':
doll.cpp:176:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  176 |     while(X.size()>s) X.pop_back();
      |           ~~~~~~~~^~
doll.cpp:177:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  177 |     while(Y.size()>s) Y.pop_back();
      |           ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 33368 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 33368 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 33368 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 33372 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 33368 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 33368 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -