Submission #1053087

#TimeUsernameProblemLanguageResultExecution timeMemory
1053087Zbyszek99Parrots (IOI11_parrots)C++17
98 / 100
70 ms1552 KiB
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i <= b; i++)

void encode(int n, int M[])
{
  int num_of_zero = 0;
  int num_of_one = 0;
  vector<int> m;
  rep(i,0,n-1) m.push_back(M[i]);
  for(auto it:m)
  {
    rep(bit,0,7)
    {
      if(it & (1 << bit)) num_of_one++;
      else num_of_zero++;
    }
  }
  if(num_of_zero < num_of_one)
  {
    rep(i,0,n-1) m[i] ^= 255;
    rep(i,0,7) send(0);
  }
  if(n > 32)
  {
    rep(j,0,(n%4)-1) m.push_back(255);
    for(int i = 0; i < (n+3)/4; i++) {
      int w = 0;
      int poz = i*4;
      if(m[poz] == 255) w += 1;
      if(m[poz+1] == 255) w += 2;
      if(m[poz+2] == 255) w += 4;
      if(m[poz+3] == 255) w += 8;
      int ans = i + (w << 4);
      if(w == 0) continue;
      send(ans);
      send(ans);
      send(ans);
      send(ans);
    }
    rep(i,0,n/2-1)
    {
      if(m[i] == 255)
      {
        continue;
      }
      rep(bit,0,7)
      {
        if(m[i] & (1 << bit))
        {
          send(bit + (i << 3));
        }
      }
    }  
    rep(i,n/2,n-1)
    {
      if(m[i] == 255)
      {
        continue;
      }
      rep(bit,0,7)
      {
        if(m[i] & (1 << bit))
        {
          send(bit + ((i-(n/2)) << 3));
          send(bit + ((i-(n/2)) << 3));
        }
      }
    }
    return;
  }
  rep(i,0,n-1)
  {
    rep(bit,0,7)
    {
      if(m[i] & (1 << bit))
      {
        send(bit + (i << 3));
      }
    }
  }    
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i <= b; i++)

void decode(int n, int l, int x[])
{
  vector<int> ans(n+4,0);
  map<int,int> zlicz;
  rep(i,0,l-1) zlicz[x[i]]++;
  if(n <= 32)
  {
    rep(i,0,l-1)
    {
      if(zlicz[x[i]] == 8) continue;
      int bit = 0;
      if(x[i] & 1) bit += 1;
      if(x[i] & 2) bit += 2;
      if(x[i] & 4) bit += 4;
      int poz = x[i] >> 3;
      ans[poz] |= (1 << bit);
    }
  }
  else
  {
    rep(i,0,l-1)
    {
      cerr << x[i] << " " << zlicz[x[i]]<<  " zap\n";
      if(zlicz[x[i]] & 1)
      {
        int bit = 0;
        if(x[i] & 1) bit += 1;
        if(x[i] & 2) bit += 2;
        if(x[i] & 4) bit += 4;
        int poz = x[i] >> 3;
        ans[poz] |= (1 << bit);    
      }
      if(zlicz[x[i]] & 2)
      {
        int bit = 0;
        if(x[i] & 1) bit += 1;
        if(x[i] & 2) bit += 2;
        if(x[i] & 4) bit += 4;
        int poz = x[i] >> 3;
        ans[poz + n/2] |= (1 << bit);    
      }
      if(zlicz[x[i]] & 4)
      {
        int blok = x[i] & (1+2+4+8);
        int is = x[i] & (16+32+64+128);
        int p = 0;
        cerr << blok << " " << is << " info255\n";
        is = (is >> 4);
        rep(j,blok*4,blok*4+3)
        {
          if(is & (1 << p)) ans[j] = 255;
          p++;
        }
      }
    }
  }
  cerr << "ans: ";
  if(zlicz[0] & 8)
  {
    rep(i,0,n-1) ans[i] ^= 255;
  }
  rep(i,0,n-1) cerr << ans[i] << " ";
  cerr << "\n";
  rep(i,0,n-1) output(ans[i]);
}
#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...