제출 #1332700

#제출 시각아이디문제언어결과실행 시간메모리
1332700QuocSensei앵무새 (IOI11_parrots)C++20
98 / 100
8 ms944 KiB
#include <bits/stdc++.h>

#define ENCODER
// #define DECODER

#define ll long long 
#define el cout << endl
#define bit(mask, i) (((mask) >> (i)) & 1)
#define BIT(n) ((1ll) << (n))
#define ii pair<int, int>
#define fi first 
#define se second

using namespace std;

const int maxlog = 8;
const int maxa = 256;

void send(int a);
void output(int b);

namespace SUBTASK_1
{
    #ifdef ENCODER
    namespace personA
    {
        void encode(int N, int M[])
        {
            int a = 0;
            for (int i = 0; i < N; i++)
                a += M[i] * BIT(i);
            send(a);
        }
    }
    #endif

    #ifdef DECODER
    namespace personB
    {
        void decode(int N, int L, int X[])
        {
            for (int i = 0; i < N; i++)
                output(bit(X[0], i));
        }
    }
    #endif
}
namespace SUBTASK_2
{
    #ifdef ENCODER
    namespace personA
    {
        void encode(int N, int M[])
        {
            for (int i = 0; i < N; i++)
                send(i * 256 + M[i]);
        }
    }
    #endif

    #ifdef DECODER
    namespace personB
    {
        void decode(int N, int L, int X[])
        {
            vector<ii> pr;
            for (int i = 0; i < L; i++)
                pr.push_back(ii(X[i] / 256, X[i] % 256));
            sort(pr.begin(), pr.end());
            for (int i = 0; i < N; i++)
                output(pr[i].se);
        }
    }
    #endif
}
namespace SUBTASK_34
{
    #ifdef ENCODER
    namespace personA
    {
        void encode(int N, int M[])
        {
            int block_size = maxa / N;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < maxlog; j++)
                    if (bit(M[i], j))
                        send(i * block_size + j);
            }
        }
    }
    #endif

    #ifdef DECODER
    namespace personB
    {
        void decode(int N, int L, int X[])
        {
            vector<ii> pr;
            int block_size = maxa / N;
            for (int i = 0; i < L; i++)
                pr.push_back(ii(X[i] / block_size, X[i] % block_size));
            sort(pr.begin(), pr.end());
            for (int i = 0, j = 0; i < N; i++)
            {
                int ans = 0;
                for (;j < L && pr[j].fi == i; j++)
                    ans += BIT(pr[j].se);
                output(ans);
            }
        }
    }
    #endif
}
namespace SUBTASK_5
{
    vector<int> a;
    vector<vector<int>> seq;

    void recur(int pos, int k, int v, int last)
    {
        seq.push_back(a);
        if (pos > k)
        {
            // for (int x : a)
            //     cout << x << ' ';
            // el;
            return ;
        }
        int ans = 0;
        for (int x = last; x <= v; x++)
        {
            a.push_back(x);
            recur(pos + 1, k, v, x);
            a.pop_back();
        }
    }
    void setup()
    {
        a.clear();
        seq.clear();
        recur(1, 7, 3, 0);
        sort(seq.begin(), seq.end());
    }

    #ifdef ENCODER
    namespace personA
    {
        void encode(int N, int M[])
        {
            int block_size = maxa / N;
            setup();

            for (int i = 0; i < N; i++)
            {
                vector<int> vt = seq[M[i]];
                for (int x : vt)
                    send(i * block_size + x);
            }
        }
    }
    #endif

    #ifdef DECODER
    namespace personB
    {
        void decode(int N, int L, int X[])
        {
            int block_size = maxa / N;
            setup();

            vector<ii> pr;
            for (int i = 0; i < L; i++)
                pr.push_back(ii(X[i] / block_size, X[i] % block_size));
            sort(pr.begin(), pr.end());
            // for (ii x : pr)
            //     cout << x.fi << ' ' << x.se, el;

            for (int i = 0, j = 0; i < N; i++)
            {
                vector<int> vt;
                for (; j < L && pr[j].fi == i; j++)
                    vt.push_back(pr[j].se);
                int val = lower_bound(seq.begin(), seq.end(), vt) - seq.begin();
                output(val);
            }
        }
    }
    #endif
}

#ifdef ENCODER
void encode(int N, int M[])
{
    SUBTASK_5::personA::encode(N, M);
}
#endif
#ifdef DECODER
void decode(int N, int L, int X[])
{
    SUBTASK_5::personB::decode(N, L, X);
}
#endif
#include <bits/stdc++.h>

// #define ENCODER
#define DECODER

#define ll long long 
#define el cout << endl
#define bit(mask, i) (((mask) >> (i)) & 1)
#define BIT(n) ((1ll) << (n))
#define ii pair<int, int>
#define fi first 
#define se second

using namespace std;

const int maxlog = 8;
const int maxa = 256;

void send(int a);
void output(int b);

namespace SUBTASK_1
{
    #ifdef ENCODER
    namespace personA
    {
        void encode(int N, int M[])
        {
            int a = 0;
            for (int i = 0; i < N; i++)
                a += M[i] * BIT(i);
            send(a);
        }
    }
    #endif

    #ifdef DECODER
    namespace personB
    {
        void decode(int N, int L, int X[])
        {
            for (int i = 0; i < N; i++)
                output(bit(X[0], i));
        }
    }
    #endif
}
namespace SUBTASK_2
{
    #ifdef ENCODER
    namespace personA
    {
        void encode(int N, int M[])
        {
            for (int i = 0; i < N; i++)
                send(i * 256 + M[i]);
        }
    }
    #endif

    #ifdef DECODER
    namespace personB
    {
        void decode(int N, int L, int X[])
        {
            vector<ii> pr;
            for (int i = 0; i < L; i++)
                pr.push_back(ii(X[i] / 256, X[i] % 256));
            sort(pr.begin(), pr.end());
            for (int i = 0; i < N; i++)
                output(pr[i].se);
        }
    }
    #endif
}
namespace SUBTASK_34
{
    #ifdef ENCODER
    namespace personA
    {
        void encode(int N, int M[])
        {
            int block_size = maxa / N;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < maxlog; j++)
                    if (bit(M[i], j))
                        send(i * block_size + j);
            }
        }
    }
    #endif

    #ifdef DECODER
    namespace personB
    {
        void decode(int N, int L, int X[])
        {
            vector<ii> pr;
            int block_size = maxa / N;
            for (int i = 0; i < L; i++)
                pr.push_back(ii(X[i] / block_size, X[i] % block_size));
            sort(pr.begin(), pr.end());
            for (int i = 0, j = 0; i < N; i++)
            {
                int ans = 0;
                for (;j < L && pr[j].fi == i; j++)
                    ans += BIT(pr[j].se);
                output(ans);
            }
        }
    }
    #endif
}
namespace SUBTASK_5
{
    vector<int> a;
    vector<vector<int>> seq;

    void recur(int pos, int k, int v, int last)
    {
        seq.push_back(a);
        if (pos > k)
        {
            // for (int x : a)
            //     cout << x << ' ';
            // el;
            return ;
        }
        int ans = 0;
        for (int x = last; x <= v; x++)
        {
            a.push_back(x);
            recur(pos + 1, k, v, x);
            a.pop_back();
        }
    }
    void setup()
    {
        a.clear();
        seq.clear();
        recur(1, 7, 3, 0);
        sort(seq.begin(), seq.end());
    }

    #ifdef ENCODER
    namespace personA
    {
        void encode(int N, int M[])
        {
            int block_size = maxa / N;
            setup();

            for (int i = 0; i < N; i++)
            {
                vector<int> vt = seq[M[i]];
                for (int x : vt)
                    send(i * block_size + x);
            }
        }
    }
    #endif

    #ifdef DECODER
    namespace personB
    {
        void decode(int N, int L, int X[])
        {
            int block_size = maxa / N;
            setup();

            vector<ii> pr;
            for (int i = 0; i < L; i++)
                pr.push_back(ii(X[i] / block_size, X[i] % block_size));
            sort(pr.begin(), pr.end());
            // for (ii x : pr)
            //     cout << x.fi << ' ' << x.se, el;

            for (int i = 0, j = 0; i < N; i++)
            {
                vector<int> vt;
                for (; j < L && pr[j].fi == i; j++)
                    vt.push_back(pr[j].se);
                int val = lower_bound(seq.begin(), seq.end(), vt) - seq.begin();
                output(val);
            }
        }
    }
    #endif
}

#ifdef ENCODER
void encode(int N, int M[])
{
    SUBTASK_5::personA::encode(N, M);
}
#endif
#ifdef DECODER
void decode(int N, int L, int X[])
{
    SUBTASK_5::personB::decode(N, L, X);
}
#endif
#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...