Submission #1171598

#TimeUsernameProblemLanguageResultExecution timeMemory
1171598ortsac앵무새 (IOI11_parrots)C++17
0 / 100
1 ms840 KiB
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define fr first
#define se second

bool isOn(int x, int i) {
  return (x & (1 << i));
}

int whichOne(int a, int b) {
  if (!a && !b) return 0;
  if (!a && b) return 1;
  if (a && !b) return 2;
  return 3;
}

void encode(int n, int m[]) {
  // {0, 0} 0 
  // {0, 1} 1
  // {1, 0} 2
  // {1, 1} 3
  vector<int> v(n*8);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 8; j++) {
      if (isOn(m[i], j)) v[i] = 1;
    }
  }
  vector<pii> q(4);
  for (int i = 0; i < 4; i++) q[i].se = i;
  for (int i = 0; i < 8*n; i += 2) {
    q[whichOne(v[i], v[i + 1])].fr++;
  }
  sort(q.begin(), q.end());
  vector<int> curr;
  for (auto u : q) curr.push_back(u.se);
  vector<int> p = {0, 1, 2, 3};
  int cnt = 0;
  while (p != curr) {
    next_permutation(p.begin(), p.end());
    cnt++;
  }
  for (int i = 0; i < 4; i++) send(cnt); // ok, now i transmitted the info of which perm this is
  for (int i = 0; i < 8*n; i += 2) {
    int x = whichOne(v[i], v[i + 1]);
    int qtd = 3;
    for (int j = 0; j < 4; j++) {
      if (curr[j] != x) qtd--;
      else break;
    }
    for (int j = 0; j < qtd; j++) send(i/2);
  }
  return;
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>

using namespace std;

void decode(int n, int l, int v[]) {
  vector<int> qtd(256);
  for (int i = 0; i < l; i++) {
    qtd[v[i]]++;
  }
  int cnt;
  for (int i = 0; i < 256; i++) {
    if (qtd[i] > 3) {
      cnt = i;
      qtd[i] -= 4;
      break;
    }
  }
  vector<int> p = {0, 1, 2, 3};
  while (cnt--) next_permutation(p.begin(), p.end());
  vector<int> ans(512);
  for (int i = 0; i < 256; i++) {
    int x = p[qtd[i]];
    // bit i*2 e i*2 = 1
    if (x == 0) {
      ans[i*2] = 0;
      ans[i*2 + 1] = 0;
    } else if (x == 1) {
      ans[i*2] = 0;
      ans[i*2 + 1] = 1;
    } else if (x == 2) {
      ans[i*2] = 1;
      ans[i*2 + 1] = 0;
    } else {
      ans[i*2] = 1;
      ans[i*2 + 1];
    }
  }
  for (int i = 0; i < n; i++) {
    int sum = 0;
    int bit = 0;
    for (int j = 8*i; j < (8*i + 8); j++) {
      if (ans[j]) sum += (1 << bit);
      bit++;
    }
    output(sum);
  }
  return;
}
#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...