Submission #951304

# Submission time Handle Problem Language Result Execution time Memory
951304 2024-03-21T15:13:38 Z andrei_boaca Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
54 ms 9592 KB
#include "Anna.h"
#include <bits/stdc++.h>
#include <vector>

using namespace std;
typedef long long ll;
namespace
{
    ll dp[105][2];
    int dir;
    vector<int> getsir(vector<char> s)
    {
        int n=s.size();
        int N=n;
        int zy=0,yx=0;
        for(int i=0;i+1<n;i++)
        {
            if(s[i]=='Z'&&s[i+1]=='Y')
                zy++;
            if(s[i]=='Y'&&s[i+1]=='X')
                yx++;
        }
        char cz='Z',cx='X';
        vector<int> rez;
        int lastz=-1;
        bool havex=0;
        for(int i=N-1;i>=0;i--)
            if(s[i]==cz)
            {
                lastz=i;
                break;
            }
        if(lastz==-1)
        {
            rez.push_back(0);
            return rez;
        }
        for(int i=0;i<N;i++)
        {
            if(s[i]==cx)
            {
                if(!havex)
                {
                    rez.push_back(1);
                    rez.push_back(0);
                }
                else
                    rez.push_back(0);
                havex=1;
                continue;
            }
            if(!havex)
            {
                rez.push_back(0);
                continue;
            }
            if(s[i]==cz&&(i==N||s[i+1]=='Y'||i==lastz))
                rez.push_back(1);
            else
                rez.push_back(0);
        }
        return rez;
    }
    vector<int> codif(vector<int> vec)
    {
        ll cnt=0;
        for(int i=0;i<vec.size();i++)
            if(vec[i]==1)
            {
                ll lft=(int)vec.size()-i-1;
                cnt+=dp[lft][0]+dp[lft][1];
            }
        //cout<<cnt<<'\n';
        vector<int> rez;
        for(int bit=43;bit>=0;bit--)
        {
            if((cnt>>bit)&1)
                rez.push_back(1);
            else
                rez.push_back(0);
        }
        return rez;
    }
}
void Anna(int N, std::vector<char> S)
{
    dp[0][0]=1;
    dp[0][1]=0;
    dp[1][0]=dp[1][1]=1;
    for(ll i=2;i<=70;i++)
    {
        dp[i][0]=dp[i-1][0]+dp[i-1][1];
        dp[i][1]=dp[i-1][0];
    }
    dir=0;
    vector<int> sol,sir;
    sir=getsir(S);
    if(sir.size()==1)
    {
        Send(sir[0]);
        return;
    }
    int nr1=0;
    /*for(int i=1;i<sir.size();i++)
        assert(sir[i]+sir[i-1]<2);*/
    for(int i=0;i<sir.size();i+=63)
    {
        vector<int> vec;
        for(int j=i;j<sir.size()&&j<i+63;j++)
            vec.push_back(sir[j]);
        while(vec.size()<63)
            vec.push_back(0);
        vector<int> t=codif(vec);
        for(int j:t)
            sol.push_back(j);
    }
    for(int i:sol)
        Send(i);
}
#include "Bruno.h"
#include <bits/stdc++.h>
#include <vector>

using namespace std;
typedef long long ll;
namespace
{
    ll depeu[105][2];
    vector<int> decod(ll num)
    {
        vector<int> rez;
        for(int i=0;i<63;i++)
        {
            ll lg=63-i-1;
            if(depeu[lg][0]+depeu[lg][1]<=num)
            {
                num-=(depeu[lg][0]+depeu[lg][1]);
                rez.push_back(1);
            }
            else
                rez.push_back(0);
        }
        return rez;
    }
}

void Bruno(int N, int L, std::vector<int> A)
{
    depeu[0][0]=1;
    depeu[0][1]=0;
    depeu[1][0]=1;
    depeu[1][1]=1;
    for(ll i=2;i<=70;i++)
    {
        depeu[i][0]=depeu[i-1][0]+depeu[i-1][1];
        depeu[i][1]=depeu[i-1][0];
    }
    vector<int> sir;
    if(L==1)
    {
        for(int i=0;i<N;i++)
            Remove(i);
        return;
    }
    for(int i=0;i<A.size();i+=44)
    {
        ll num=0;
        for(int j=i;j<A.size()&&j<i+44;j++)
            num=num*2LL+A[j];
        //cout<<num<<'\n';
        vector<int> vals=decod(num);
        for(int j=0;j<vals.size()&&sir.size()<N+1;j++)
            sir.push_back(vals[j]);
    }
    vector<int> aux;
    int elim=-1;
    for(int i=0;i<sir.size();i++)
        if(sir[i]==1)
        {
            elim=i+1;
            break;
        }
    for(int i=0;i<sir.size();i++)
        if(i!=elim)
            aux.push_back(sir[i]);
    /*for(int i:aux)
        cout<<i<<' ';
    cout<<'\n';*/
    A=aux;
    int lft=-1;
    for(int i=0;i<A.size();i++)
        if(A[i]==1)
        {
            lft=i;
            break;
        }
    //assert(A.size()==N);
    if(lft==-1)
    {
        for(int i=0;i<N;i++)
            Remove(i);
        return;
    }
    for(int i=0;i<lft;i++)
        Remove(i);
    for(int i=lft+1;i<A.size();i++)
        if(A[i]==1)
        {
            for(int j=i-1;A[j]==0;j--)
                Remove(j);
            Remove(i);
        }
    for(int i=N-1;A[i]==0;i--)
        Remove(i);
    Remove(lft);
}

Compilation message

Anna.cpp: In function 'std::vector<int> {anonymous}::codif(std::vector<int>)':
Anna.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int i=0;i<vec.size();i++)
      |                     ~^~~~~~~~~~~
Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:106:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for(int i=0;i<sir.size();i+=63)
      |                 ~^~~~~~~~~~~
Anna.cpp:109:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |         for(int j=i;j<sir.size()&&j<i+63;j++)
      |                     ~^~~~~~~~~~~
Anna.cpp:103:9: warning: unused variable 'nr1' [-Wunused-variable]
  103 |     int nr1=0;
      |         ^~~

Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0;i<A.size();i+=44)
      |                 ~^~~~~~~~~
Bruno.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int j=i;j<A.size()&&j<i+44;j++)
      |                     ~^~~~~~~~~
Bruno.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int j=0;j<vals.size()&&sir.size()<N+1;j++)
      |                     ~^~~~~~~~~~~~
Bruno.cpp:53:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |         for(int j=0;j<vals.size()&&sir.size()<N+1;j++)
      |                                    ~~~~~~~~~~^~~~
Bruno.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=0;i<sir.size();i++)
      |                 ~^~~~~~~~~~~
Bruno.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i=0;i<sir.size();i++)
      |                 ~^~~~~~~~~~~
Bruno.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i=0;i<A.size();i++)
      |                 ~^~~~~~~~~
Bruno.cpp:87:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int i=lft+1;i<A.size();i++)
      |                     ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 780 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 0 ms 792 KB Output is correct
4 Correct 0 ms 780 KB Output is correct
5 Correct 0 ms 780 KB Output is correct
6 Correct 0 ms 780 KB Output is correct
7 Correct 0 ms 792 KB Output is correct
8 Correct 0 ms 788 KB Output is correct
9 Correct 1 ms 792 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
11 Correct 0 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 9064 KB Output is correct
2 Correct 39 ms 8860 KB Output is correct
3 Correct 39 ms 8956 KB Output is correct
4 Correct 43 ms 8892 KB Output is correct
5 Correct 39 ms 8908 KB Output is correct
6 Correct 40 ms 9016 KB Output is correct
7 Correct 54 ms 9016 KB Output is correct
8 Correct 41 ms 9068 KB Output is correct
9 Correct 43 ms 9160 KB Output is correct
10 Correct 40 ms 9068 KB Output is correct
11 Correct 39 ms 9120 KB Output is correct
12 Correct 44 ms 9156 KB Output is correct
13 Correct 47 ms 8932 KB Output is correct
14 Correct 47 ms 9036 KB Output is correct
15 Correct 44 ms 8892 KB Output is correct
16 Correct 46 ms 8968 KB Output is correct
17 Correct 34 ms 6756 KB Output is correct
18 Correct 34 ms 6772 KB Output is correct
19 Correct 46 ms 9140 KB Output is correct
20 Correct 43 ms 9344 KB Output is correct
21 Correct 43 ms 9432 KB Output is correct
22 Correct 48 ms 9440 KB Output is correct
23 Correct 43 ms 9500 KB Output is correct
24 Correct 45 ms 9296 KB Output is correct
25 Correct 48 ms 9412 KB Output is correct
26 Correct 34 ms 7180 KB Output is correct
27 Correct 47 ms 9484 KB Output is correct
28 Correct 37 ms 7200 KB Output is correct
29 Correct 47 ms 9592 KB Output is correct
30 Correct 37 ms 7132 KB Output is correct
31 Correct 53 ms 9504 KB Output is correct
32 Correct 43 ms 9448 KB Output is correct
33 Correct 47 ms 9496 KB Output is correct