Submission #593047

# Submission time Handle Problem Language Result Execution time Memory
593047 2022-07-10T09:44:36 Z cadmiumsky Parrots (IOI11_parrots) C++14
0 / 100
2000 ms 89600 KB
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;

#define Huge amongus
#define transmit transmitamongus
#define maxint maxintamongus
#define nbit nbitamongus
#define ncr ncramongus
int transmit = 280, maxint = 255, nbit = 8;

#define nmax (transmit + maxint)


class Huge {
  vector<int> num;
  public:
    void print() {
      for(int i = num.size() - 1; i >= 0; i--)
        cerr << num[i];
      cerr << '\n';
    }
    int get(int poz) const { if(poz >= num.size()) return 0; return num[poz]; }
    void shrink_to_fit() {
      while(!num.empty() && num.back() == 0)
        num.pop_back();
      return;
    }
    bool operator < (const Huge& other) const {
      if(num.size() < other.num.size()) return 1;
      if(num.size() > other.num.size()) return 0;
      for(int i = num.size() - 1; i >= 0; i--)  
        if(num[i] < other.num[i])
          return 1;
        else if(num[i] > other.num[i])
          return 0;
      return 0;
    }
    bool operator > (const Huge& other) const { return (other < *this); }
    bool operator <= (const Huge& other) const { return !(*this > other); }
    bool operator >= (const Huge& other) const { return !(*this < other); }
    Huge() {
      num.clear();
    }
    Huge(int x) {
      assert(x < 10);
      num.clear();
      if(x != 0)
        num.push_back(x);
    }
    int operator % (const int& x) { assert(x == 2); return num[0] % 2; }
    void operator *= (const int& x) {
      int t = 0, len = num.size();
      for(int i = 0; i < len; i++)
        num[i] = (t = (t / 10 + num[i] * x)) % 10;
      t /= 10;
      while(t) {
        num.push_back(t % 10);
        t /= 10;
      }
    }
    void operator /=(const int& x) {
      int t = 0;
      for(int i = num.size() - 1; i >= 0; i--) {
        num[i] = (t = ((t % x) * 10 + num[i])) / x;
      }
      shrink_to_fit();
    }
    void operator <<=(const int& x)  {
      if(num.empty())
        return;
      for(int i = 0; i < x; i++)
        *this *= 2;
      return;
    }
    void operator >>=(const int& x)  {
      for(int i = 0; i < x && !num.empty(); i++)
        *this /= 2;
      return;
    }
    Huge operator +(const Huge& other) const {
      Huge rez;
      int t = 0, len = max(other.num.size(), num.size());
      for(int i = 0; i < len; i++) {
        rez.num.push_back((t = t / 10 + other.get(i) + get(i)) % 10);
      }
      t /= 10;
      while(t) {
        rez.num.push_back(t % 10);
        t /= 10;
      }
      return rez;
    }
    Huge operator -(const Huge& other) const {
      if(*this < other)
        assert(false);
      Huge rez;
      int t = 0;
      for(int i = 0; i < num.size(); i++) {
        rez.num.push_back(((t = (num[i] - other.get(i) - t)) + 10) % 10);
        if(t < 0) t = 1;
        else t = 0;
      }
      rez.shrink_to_fit();
      return rez;
    }
    void operator -=(const Huge& other) { *this = *this - other; }
    void operator +=(const Huge& other) { *this = *this + other; }
    void operator +=(int x) {*this = *this + Huge(x);}
    void operator -=(int x) {*this = *this + Huge(x);}
};

void encode(int N, int M[]) {
  transmit = N * 5;
  vector<vector<Huge>> ncr(nmax + 1, vector<Huge>(nmax + 1));
  ncr[0][0] = 1;
  for(int i = 1; i <= nmax; i++) {
    ncr[i][0] = 1;
    ncr[i][i] = 1;
    for(int j = 1; j < i; j++)
      ncr[i][j] = ncr[i - 1][j] + ncr[i - 1][j - 1];
  }
  Huge mine;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < nbit; j++)
      mine *= 2,
      mine += ((M[i] & (1 << j)) > 0);
    //mine.print();
  }
  //cerr << "We sent: ";
  //mine.print();
  int sent = transmit;
  for(int i = nmax; i >= 1; i--) {
    if(mine >= ncr[i - 1][sent]) {
      mine -= ncr[i - 1][sent];
      send(i - sent);
      //cerr << "Sent " << i - sent << '\n';
      sent--;
    }
  }
  //cerr << sent << '\n';
  return;
}
#undef nmax
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
int transmit, maxint = 255, nbit = 8;

#define nmax (transmit + maxint)

class Huge {
  vector<int> num;
  public:
    void print() {
      for(int i = num.size() - 1; i >= 0; i--)
        cerr << num[i];
      cerr << '\n';
    }
    int get(int poz) const { if(poz >= num.size()) return 0; return num[poz]; }
    void shrink_to_fit() {
      while(!num.empty() && num.back() == 0)
        num.pop_back();
      return;
    }
    bool operator < (const Huge& other) const {
      if(num.size() < other.num.size()) return 1;
      if(num.size() > other.num.size()) return 0;
      for(int i = num.size() - 1; i >= 0; i--)  
        if(num[i] < other.num[i])
          return 1;
        else if(num[i] > other.num[i])
          return 0;
      return 0;
    }
    bool operator > (const Huge& other) const { return (other < *this); }
    bool operator <= (const Huge& other) const { return !(*this > other); }
    bool operator >= (const Huge& other) const { return !(*this < other); }
    Huge() {
      num.clear();
    }
    Huge(int x) {
      assert(x < 10);
      num.clear();
      if(x != 0)
        num.push_back(x);
    }
    int operator % (const int& x) { assert(x == 2); return num[0] % 2; }
    void operator *= (const int& x) {
      int t = 0, len = num.size();
      for(int i = 0; i < len; i++)
        num[i] = (t = (t / 10 + num[i] * x)) % 10;
      t /= 10;
      while(t) {
        num.push_back(t % 10);
        t /= 10;
      }
    }
    void operator /=(const int& x) {
      int t = 0;
      for(int i = num.size() - 1; i >= 0; i--) {
        num[i] = (t = ((t % x) * 10 + num[i])) / x;
      }
      shrink_to_fit();
    }
    void operator <<=(const int& x)  {
      if(num.empty())
        return;
      for(int i = 0; i < x; i++)
        *this *= 2;
      return;
    }
    void operator >>=(const int& x)  {
      for(int i = 0; i < x && !num.empty(); i++)
        *this /= 2;
      return;
    }
    Huge operator +(const Huge& other) const {
      Huge rez;
      int t = 0, len = max(other.num.size(), num.size());
      for(int i = 0; i < len; i++) {
        rez.num.push_back((t = t / 10 + other.get(i) + get(i)) % 10);
      }
      t /= 10;
      while(t) {
        rez.num.push_back(t % 10);
        t /= 10;
      }
      return rez;
    }
    Huge operator -(const Huge& other) const {
      if(*this < other)
        assert(false);
      Huge rez;
      int t = 0;
      for(int i = 0; i < num.size(); i++) {
        rez.num.push_back(((t = (num[i] - other.get(i) - t)) + 10) % 10);
        if(t < 0) t = 1;
        else t = 0;
      }
      rez.shrink_to_fit();
      return rez;
    }
    void operator -=(const Huge& other) { *this = *this - other; }
    void operator +=(const Huge& other) { *this = *this + other; }
    void operator +=(int x) {*this = *this + Huge(x);}
    void operator -=(int x) {*this = *this + Huge(x);}
};


void decode(int N, int L, int X[]) {
  transmit = N * 5;
  vector<vector<Huge>> ncr(nmax + 1, vector<Huge>(nmax + 1));
  ncr[0][0] = 1;
  for(int i = 1; i <= nmax; i++) {
    ncr[i][0] = 1;
    ncr[i][i] = 1;
    for(int j = 1; j < i; j++)
      ncr[i][j] = ncr[i - 1][j] + ncr[i - 1][j - 1];
  }
  int b;
  vector<int> got;
  for(int i=0; i<L; i++) {
    got.push_back(X[i]);
  }
  sort(got.begin(), got.end());
  int nth = 0;
  Huge rez;
  for(auto i : got) {
    nth++;
    i += nth;
    rez += ncr[i - 1][nth];
  }
  //cerr << "We received: ";
  //rez.print();
  vector<int> found;
  for(int i = 0; i < N; i++) {
    found.push_back(0);
    for(int j = 0; j < nbit; j++) {
      //cerr << "one ";
      found.back() = found.back() * 2 + (rez % 2),
      rez /= 2;
    }
    //rez.print();
  }
  while(!found.empty())
    //cerr << found.back() << ' ',
    output(found.back()),
    found.pop_back();
  //cerr << '\n';
  return;
}
#undef nmax

Compilation message

encoder.cpp: In member function 'int amongus::get(int) const':
encoder.cpp:24:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     int get(int poz) const { if(poz >= num.size()) return 0; return num[poz]; }
      |                                 ~~~~^~~~~~~~~~~~~
encoder.cpp: In member function 'amongus amongus::operator-(const amongus&) const':
encoder.cpp:100:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |       for(int i = 0; i < num.size(); i++) {
      |                      ~~^~~~~~~~~~~~

decoder.cpp: In member function 'int Huge::get(int) const':
decoder.cpp:17:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     int get(int poz) const { if(poz >= num.size()) return 0; return num[poz]; }
      |                                 ~~~~^~~~~~~~~~~~~
decoder.cpp: In member function 'Huge Huge::operator-(const Huge&) const':
decoder.cpp:93:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |       for(int i = 0; i < num.size(); i++) {
      |                      ~~^~~~~~~~~~~~
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:118:7: warning: unused variable 'b' [-Wunused-variable]
  118 |   int b;
      |       ^
# Verdict Execution time Memory Grader output
1 Runtime error 200 ms 41036 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 862 ms 41480 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 848 ms 41388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 849 ms 41412 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1206 ms 58624 KB Execution killed with signal 11
2 Execution timed out 2009 ms 34172 KB Time limit exceeded
3 Execution timed out 2024 ms 35436 KB Time limit exceeded
4 Execution timed out 2082 ms 60264 KB Time limit exceeded
5 Execution timed out 2081 ms 80668 KB Time limit exceeded
6 Execution timed out 2092 ms 87292 KB Time limit exceeded
7 Execution timed out 2085 ms 89600 KB Time limit exceeded