Submission #931297

# Submission time Handle Problem Language Result Execution time Memory
931297 2024-02-21T14:42:16 Z HuyQuang_re_Zero Mechanical Doll (IOI18_doll) C++14
16 / 100
92 ms 41904 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];
vector <int> res,X,Y,to[maxn];
/*
void answer(vector <int> res,vector <int> X,vector <int> Y)
{
    cerr<<X.size()<<" "<<Y.size()<<'\n';
    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++)
    {
       // cerr<<i<<" "<<a.X.size()<<" "<<numa[i]<<" "<<res.X.size()<<'\n';
        res.X[numa[i]]=numa[a.X[i]];
       //  cerr<<i<<" "<<a.X.size()<<" "<<numa[i]<<" "<<X.size()<<'\n';
        res.Y[numa[i]]=numa[a.Y[i]];
    }
    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]]=numb[b.X[i]];
        res.Y[numb[i]]=numb[b.Y[i]];
    }
    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 create_circuit(int _m,vector <int> a)
{
    m=_m; n=a.size();
    int ok=1;
    for(i=0;i<n;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[0];
    X.resize(2*n); Y.resize(2*n);
    if(ok) sub1();
}
/*
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:73: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]
   73 |         for(int i=0;i<a.sink.size()-2;i++)
      |                     ~^~~~~~~~~~~~~~~~
doll.cpp:84: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]
   84 |         for(int i=0;i<a.sink.size();i++)
      |                     ~^~~~~~~~~~~~~~
doll.cpp: In function 'void sub1()':
doll.cpp:114:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |         for(i=0;i<to[k].size();i++)
      |                 ~^~~~~~~~~~~~~
doll.cpp:121:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  121 |     while(X.size()>s) X.pop_back();
      |           ~~~~~~~~^~
doll.cpp:122:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  122 |     while(Y.size()>s) Y.pop_back();
      |           ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27224 KB Output is correct
2 Correct 29 ms 32512 KB Output is correct
3 Correct 23 ms 32076 KB Output is correct
4 Correct 7 ms 27484 KB Output is correct
5 Correct 14 ms 28252 KB Output is correct
6 Correct 31 ms 34392 KB Output is correct
7 Correct 6 ms 27224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27224 KB Output is correct
2 Correct 29 ms 32512 KB Output is correct
3 Correct 23 ms 32076 KB Output is correct
4 Correct 7 ms 27484 KB Output is correct
5 Correct 14 ms 28252 KB Output is correct
6 Correct 31 ms 34392 KB Output is correct
7 Correct 6 ms 27224 KB Output is correct
8 Correct 47 ms 35128 KB Output is correct
9 Correct 49 ms 35700 KB Output is correct
10 Correct 77 ms 39504 KB Output is correct
11 Correct 6 ms 27224 KB Output is correct
12 Correct 6 ms 27228 KB Output is correct
13 Correct 6 ms 27248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27224 KB Output is correct
2 Correct 29 ms 32512 KB Output is correct
3 Correct 23 ms 32076 KB Output is correct
4 Correct 7 ms 27484 KB Output is correct
5 Correct 14 ms 28252 KB Output is correct
6 Correct 31 ms 34392 KB Output is correct
7 Correct 6 ms 27224 KB Output is correct
8 Correct 47 ms 35128 KB Output is correct
9 Correct 49 ms 35700 KB Output is correct
10 Correct 77 ms 39504 KB Output is correct
11 Correct 6 ms 27224 KB Output is correct
12 Correct 6 ms 27228 KB Output is correct
13 Correct 6 ms 27248 KB Output is correct
14 Correct 92 ms 41904 KB Output is correct
15 Correct 49 ms 36288 KB Output is correct
16 Correct 71 ms 39976 KB Output is correct
17 Correct 7 ms 29276 KB Output is correct
18 Correct 6 ms 29272 KB Output is correct
19 Correct 6 ms 29276 KB Output is correct
20 Correct 79 ms 41376 KB Output is correct
21 Correct 7 ms 29272 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 25180 KB Wrong Answer: answered not exactly once
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 25180 KB Wrong Answer: answered not exactly once
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 25180 KB Wrong Answer: answered not exactly once
2 Halted 0 ms 0 KB -