Submission #951302

# Submission time Handle Problem Language Result Execution time Memory
951302 2024-03-21T15:12:25 Z andrei_boaca Ancient Machine (JOI21_ancient_machine) C++17
0 / 100
46 ms 9660 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:104:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     for(int i=1;i<sir.size();i++)
      |                 ~^~~~~~~~~~~
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++)
      |                 ~^~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from Bruno.cpp:2:
Bruno.cpp:78:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |     assert(A.size()==N);
      |            ~~~~~~~~^~~
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 0 ms 1032 KB Output is correct
2 Correct 0 ms 796 KB Output is correct
3 Correct 0 ms 1036 KB Output is correct
4 Correct 0 ms 796 KB Output is correct
5 Correct 0 ms 796 KB Output is correct
6 Correct 1 ms 796 KB Output is correct
7 Correct 0 ms 796 KB Output is correct
8 Correct 1 ms 780 KB Output is correct
9 Correct 1 ms 796 KB Output is correct
10 Correct 0 ms 796 KB Output is correct
11 Runtime error 1 ms 796 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 9148 KB Output is correct
2 Correct 40 ms 9496 KB Output is correct
3 Correct 40 ms 9372 KB Output is correct
4 Correct 40 ms 9604 KB Output is correct
5 Correct 39 ms 9632 KB Output is correct
6 Correct 40 ms 9616 KB Output is correct
7 Correct 40 ms 9572 KB Output is correct
8 Correct 39 ms 9456 KB Output is correct
9 Correct 44 ms 9660 KB Output is correct
10 Correct 40 ms 9608 KB Output is correct
11 Correct 46 ms 9584 KB Output is correct
12 Correct 40 ms 9584 KB Output is correct
13 Correct 45 ms 9452 KB Output is correct
14 Correct 43 ms 9308 KB Output is correct
15 Correct 44 ms 9248 KB Output is correct
16 Correct 40 ms 9260 KB Output is correct
17 Correct 33 ms 6924 KB Output is correct
18 Correct 33 ms 7240 KB Output is correct
19 Runtime error 17 ms 6280 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -