Submission #1337913

#TimeUsernameProblemLanguageResultExecution timeMemory
1337913alexddFortune Telling 3 (JOI25_fortune3)C++20
71 / 100
328 ms1052 KiB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;

namespace
{
    const int ULT = 8;
    const int INIT = 5;
    vector<vector<int>> precalc()
    {
        vector<vector<int>> configs;
        for(int mask=0;mask<(1<<(ULT+INIT));mask++)
        {
            if(__builtin_popcount(mask) == ULT)
            {
                vector<int> aux(INIT + 1, 0);
                int cnt0 = 0;
                for(int i=0;i<ULT+INIT;i++)
                {
                    if((1<<i)&mask)
                    {
                        aux[cnt0]++;
                    }
                    else
                    {
                        cnt0++;
                    }
                }
                assert(cnt0 == INIT);
                configs.push_back(aux);
            }
        }
        return configs;
    }
}

void Anna(int N)
{
    vector<vector<int>> configs = precalc();
    assert(configs.size() > 900);

    int prec = -1;
    int curpoz = 0, cnt1 = 0, cnt0 = 0;
    int endgame = 0, puse1 = 0, puse0 = 0;
    vector<int> endgame_config;
    for(int pas=1;pas<=N;pas++)
    {
        int val = DrawCard(prec);
        prec = -1;

        if(pas >= N - ULT + 1)//endgame
        {
            if(pas == N - ULT + 1)
            {
                if(cnt0 >= INIT && cnt1 >= INIT)
                {
                    endgame = 1;
                    endgame_config = configs[cnt1];

                    //for(int x:endgame_config) cout<<x<<" ";cout<<" endgame_config\n";
                }
                else if(cnt0 < INIT)
                {
                    assert(cnt1 >= INIT);
                    endgame = 2;
                }
                else if(cnt1 < INIT)
                {
                    assert(cnt0 >= INIT);
                    endgame = 3;
                }
                else
                    assert(0);
            }

            if(endgame == 1)
            {
                if(val == 1)
                {
                    for(int b=0;b<endgame_config.size();b++)
                    {
                        if(endgame_config[b] > 0)
                        {
                            endgame_config[b]--;
                            prec = puse1 + b;
                            break;
                        }
                    }
                    assert(prec != -1);
                    puse1++;
                }
                else
                {
                    for(int b=0;b<endgame_config.size();b++)
                    {
                        if(endgame_config[b] > 0)
                        {
                            endgame_config[b]--;
                            prec = (puse1 + INIT) + puse0 + b;
                            break;
                        }
                    }
                    assert(prec != -1);
                    puse0++;
                }
            }
            else if(endgame == 2)
            {
                if(val == 1)
                    prec = curpoz;
            }
            else if(endgame == 3)
            {
                if(val == 0)
                    prec = 0;
            }
        }
        else
        {
            if(val == 1)
            {
                cnt1++;
                if(cnt1 <= INIT)
                    prec = curpoz;
            }
            else
            {
                cnt0++;
                if(cnt0 <= INIT)
                    prec = 0;
            }
        }

        if(prec != -1)
            curpoz++;
    }
    DrawCard(prec);
}
#include "Bruno.h"

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

namespace
{
    const int ULT = 8;
    const int INIT = 5;
    vector<vector<int>> precalc()
    {
        vector<vector<int>> configs;
        for(int mask=0;mask<(1<<(ULT+INIT));mask++)
        {
            if(__builtin_popcount(mask) == ULT)
            {
                vector<int> aux(INIT + 1, 0);
                int cnt0 = 0;
                for(int i=0;i<ULT+INIT;i++)
                {
                    if((1<<i)&mask)
                    {
                        aux[cnt0]++;
                    }
                    else
                    {
                        cnt0++;
                    }
                }
                configs.push_back(aux);
            }
        }
        return configs;
    }
}

int Bruno(int N, int L, std::vector<int> C)
{
    //for(int i=0;i<L;i++) cout<<C[i]<<" "; cout<<" C\n";

    vector<vector<int>> configs = precalc();

    if(L < 2*INIT + ULT)//special endgame
    {
        int cnt0 = 0, cnt1 = 0;
        for(int i=0;i<L;i++)
        {
            if(C[i] == 1)
                cnt1++;
            else
                cnt0++;
        }
        if(cnt0 < INIT)
        {
            assert(cnt1 >= INIT);
            int tot0 = cnt0 + (ULT - (cnt1 - INIT));
            return N - tot0;
        }
        else
        {
            assert(cnt0 >= INIT);
            int tot1 = cnt1 + (ULT - (cnt0 - INIT));
            return tot1;
        }
    }
    else
    {
        vector<bool> isfixed(L+2, 0);

        int aux = 0;
        for(int i=0;i<L;i++)
        {
            if(C[i] == 0)
            {
                aux++;
                if(aux <= INIT)
                    isfixed[i] = 1;
            }
        }
        aux = 0;
        for(int i=L-1;i>=0;i--)
        {
            if(C[i] == 1)
            {
                aux++;
                if(aux <= INIT)
                    isfixed[i] = 1;
            }
        }

        vector<int> myconfig(INIT+1, 0);
        for(int i=0;i<L;i++)
        {
            if(!isfixed[i])
            {
                int cntle = 0;
                for(int j=0;j<i;j++)
                    if(isfixed[j] && C[j] != C[i])
                        cntle++;
                myconfig[cntle]++;
            }
        }

        //for(int x:myconfig) cout<<x<<" ";cout<<" myconfig\n";

        int rez = -1;

        for(int i=0;i<configs.size();i++)
        {
            if(configs[i] == myconfig)
            {
                rez = i;
                break;
            }
        }
        assert(rez != -1);

        for(int i=0;i<L;i++)
            if(!isfixed[i] && C[i] == 1)
                rez++;

        return rez;
    }
}

Compilation message (stderr)

# 1번째 컴파일 단계

grader_anna.cpp: In function 'int main()':
grader_anna.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d %d", &Q, &stubN);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~

# 2번째 컴파일 단계

grader_bruno.cpp: In function 'int main()':
grader_bruno.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%d %d", &Q, &N);
      |     ~~~~~^~~~~~~~~~~~~~~~~
grader_bruno.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf(" %d", &L);
      |         ~~~~~^~~~~~~~~~~
grader_bruno.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |             scanf(" %d", &C[i]);
      |             ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...